What takes up more memory?
So, you are asking about the size of the view in memory ..net uses UTF-16 for strings, which means that your example will be represented by 14 bytes, as seen in this hex dump (UTF-16LE):
4d 00 79 00 20 00 54 00 65 00 78 00 74 00
The size of the byte array will depend on the encoding you use to represent the text. If you are using UTF-16 , for example
Encoding.Unicode.GetBytes(string)
you obviously get the same 14 bytes. If you are using UTF-8 :
Encoding.UTF8.GetBytes(string)
you will get an array of 7 bytes:
4d 79 20 54 65 78 74
This is the same size (and same representation) as ASCII , because your example uses only ASCII encoded characters. All of these characters are, by definition, the same in UTF-8.
Now, if you use non-ASCII characters , say Japanese "ζ₯", 3 bytes are required for UTF-8 encoding:
e6 97 a5
UTF-16 only needs 2 bytes:
e5 65
Attempting to convert a Japanese character to ASCII will throw an exception or just use "?" depending on how you configure Encoding , because ASCII cannot represent anything other than ASCII characters.
Another slightly different example is the European character "Γ€". 2 bytes in UTF-8:
c3 a4
UTF-16 also has 2 bytes:
e4 00
ASCII cannot represent this character.
To summarize, the memory consumed depends on the actual data in your lines and what encoding you use to represent it .
All of the above says about memory consumption for raw data , note that to calculate the total memory consumption, you also need to include metadata strong>, which is part of each array and row, for example, its length , and in the case of .net-lines - also a null terminator (2 additional bytes with a value of "0"). The number of bytes for the metadata is constant and relatively small, so any difference between a string and an array will only matter if you have tons of very small texts.