2 ms·
All strings in C# are UTF-16. However, it exposes the encoding directly as a sequence of 16-bit ints. In other words, if you iterate over a string or index it,
by int_19h 10y ago
All strings in C# are UTF-16.
However, it exposes the encoding directly as a sequence of 16-bit ints. In other words, if you iterate over a string or index it, you're getting those, and not codepoints (i.e. it doesn't account for surrogate pairs).
Note that this only applies to iteration and indexing. All string functions do understand surrogates properly.
On the other hand, C# (or rather .NET) has a way to iterate over text elements in a string. This is one level higher than code points, in that it folds combining characters:
https://msdn.microsoft.com/en-us/library/system.globalization.stringinfo(v=vs.110).aspx https://msdn.microsoft.com/en-us/library/system.globalizatio...