C#中 char、byte、string

var str = "我是中国人";
var str1 = "abc";
char[] chars = str.ToCharArray();
char[] chars1 = str1
.ToCharArray();
byte[] bytes = Encoding.Default.GetBytes(chars);
byte[] bytes1 =
Encoding.Default.GetBytes(chars1);
var newStr = Encoding.Default.GetString(bytes);
Results: chars equal char [5] { 'I', 'a', 'in', 'country', 'person'} 
    chars1 equal char [. 3] { 'A', 'B', 'C'}
    bytes equal to byte [10] {206, 210, 202, 199, 214, 208, 185, 250, 200 is, 203}
    bytes 1 equal to byte [. 3] {97, 98, 99}
    newStr equal to "I am Chinese"

analysis:
  1, char Chinese characters can be displayed, not byte to
  2, the char to any one of a character takes, Chinese accounted byte to 2, representing an English or other
  3, are interchangeable between the three types
  4, byte to ascii code array shows

Guess you like

Origin www.cnblogs.com/az4215/p/11389841.html