Compact strings in the CLR

added by DotNetKicks
9/19/2016 2:39:12 PM

2 Kicks, 442 Views

In the CLR strings are stored as a sequence of UTF-16 code units, i.e. an array of char items. So if we have the string 'testing', in memory it looks like this: But look at all those zero's, wouldn't it be more efficient if it could be stored like this instead?