You are missing one important thing: .NET
char
, which is the
ToChar()
return type is
not ASCII
. All .NET is based on Unicode; ASCII is only supported as the encoding for streams and using it entails the loss of data in the general case of string data.
One more thing: never use multiple concatenation ('+' operator). It's result is always string, and string is
immutable. Do I have to explain the consequence? You copy the growing string back and forth as a whole, very inefficient. Generally, all your lines with
SendData
are too ad-hoc and hard-coded to be acceptable. Get rid of it. If this is really a constant data, it should be written as a single string literal, without any "Convert".
The final answer to your question depends on what you are going to do with send characters. Yes, when you convert integer to char, you get a Unicode character with the corresponding
code point value. If the value happens to be in the ASCII range (which is only 0 to 255), the character will be in the ASCII subset of Unicode. You need to learn how Unicode works — this is not encoding at all, only the UTFs are, and different UTFs gives different binary representation of the same string of code points. Unicode defines mapping between code points, which are understood as mathematical integers abstracted from their computer representations, and characters as cultural entities, abstracted from the detail of their graphical representations. Computer-related representation is defined by UTFs.
If something where you send data expects exactly ASCII, it may not work. So, please see:
http://msdn.microsoft.com/en-us/library/system.text.encoding.aspx[
^].
—SA