sizeof empty string in C#

c#, string

Solution

It's 18 bytes:

16 bytes of memory + 2 bytes per character allocated + 2 bytes for the final null character.

Note that this was written about .Net 1.1.

The `m_ArrayLength` field was removed in .Net 4.0 (you can see this in the reference source)

Problem

In Java, an empty string is 40 bytes. In Python it's 20 bytes. How big is an empty string object in C#? I cannot do `sizeof`, and I don't know how else to find out. Thanks.

Original source

Related problems