【转】C# String 与 Char[] 数组 相互转换

时间:2022-10-10 07:21:04

源地址:http://blog.csdn.net/razilfelix/article/details/52289663

string 转换成 Char[]
  string ss = "abcdefg";
  char[] cc = ss.ToCharArray();

Char[] 转换成string
  string s = new string(cc);

byte[] 与 string 之间的转换
  byte[] bb = Encoding.UTF8.GetBytes(ss);
  string s = Encoding.UTF8.GetString(bb);

byte[] 与 char[] 之间的转换

byte[] bb;

char[] cc = Encoding.ASCII.GetChars(bb);

byte[] bb = Encoding.ASCII.GetBytes(cc);