How much space does string.Empty take in CLR?
I’m guessing it’s just one byte for the NULL character.
How much space does string.Empty take in CLR? I’m guessing it’s just one byte
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No, the string is a complete object, with an object header (containing a type reference, sync block etc), length, and whatever characters are required… which will be a single null character (two bytes) and appropriate padding to round up to 4 or 8 bytes overall.
Note that although strings in .NET have a length field, they’re still null-terminated for the sake of interop. The null character is not included in the length.
Of course,
string.Emptywill only refer to a single object no matter how many times you use it… but the reference will be 4 or 8 bytes, so if you have:that will be three references (12 or 24 bytes) all referring to the same object (which is probably around 20 or 24 bytes in size).