I wish to know how to calculate the size of string data type. says what is the size of s under the following scenario?
string s="";
string s="1";
string s="12";
If possible, can point to a website mentioned this?
I wish to know how to calculate the size of string data type. says what is the size of s under the following scenario?
string s="";
string s="1";
string s="12";
If possible, can point to a website mentioned this?
 
    
     
    
    Refer to this link: How to know the size of the string in bytes?
System.Text.Encoding.Unicode.GetByteCount(s);
System.Text.Encoding.ASCII.GetByteCount(s);
or from msdn: http://msdn.microsoft.com/en-us/library/system.string.aspx
 
    
     
    
    It is not clear from your question what you meant.
If by size you mean how many characters, then Length is the property you are looking for
"".Length   // 0
"1".Length  // 1
"12".Length // 2
If by size you mean how many bytes then this is dependant on encoding and you can use the answer Snake Eyes has given
Encoding.Unicode.GetByteCount("")   // 0
Encoding.UTF8.GetByteCount("")      // 0
Encoding.Unicode.GetByteCount("1")  // 2
Encoding.UTF8.GetByteCount("1")     // 1
Encoding.Unicode.GetByteCount("12") // 4
Encoding.UTF8.GetByteCount("12")    // 2
If by size you mean value of the number then you will need to parse the text
Int32.Parse("")   // FormatException: Input string was not in a correct format
Int32.Parse("1")  // 1
Int32.Parse("12") // 12
 
    
    LMGTFY
Anything and everything string http://msdn.microsoft.com/en-us/library/system.string.aspx
String Length http://msdn.microsoft.com/en-us/library/system.string.length.aspx
String number of bytes (and string to byte array is covered in examples) http://msdn.microsoft.com/en-us/library/w3739zdy(v=vs.110).aspx
