Just wondering why do we have char type of 2 bytes size in C# (.NET) unlike 1 byte in other programming languages?
Just wondering why do we have char type of 2 bytes size in C#
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A char is unicode in C#, therefore the number of possible characters exceeds 255. So you’ll need two bytes.
Extended ASCII for example has a 255-char set, and can therefore be stored in one single byte. That’s also the whole purpose of the
System.Text.Encodingnamespace, as different systems can have different charsets, and char sizes. C# can therefore handle one/four/etc. char bytes, but Unicode UTF-16 is default.