for (int i = 0; i < chars.Length; i++)
{
char value = chars[i];
byte highPart = (byte)(value >> 8);
byte lowPart = (byte)(value & 0xFF);
bytes[2 * i] = lowPart;
bytes[2 * i + 1] = highPart;
}
return bytes;
}
P.S.
The code is not well-optimized, but i think that the idea is clear
( the same idea as in mistake in file UserStringHeap.cs - mistake in
reading strings; mistake was fixed by the patch )