The default encoding is UTF8, which can contain 1-4 bytes of space per character.
charCount and byteCount will not be equal if any character in string s uses more than 1 byte.
To force 4 bytes, you can check with Unicode encoding, then byteCount will be = 8.
int byteCount = System.Text.Encoding.Unicode.GetBytes(s).Length;
James kyburz
source share