字符串
1 static void Main(string[] args) 2 { 3 //字符串的不可变性 4 string name = "张三"; 5 name = "孙全"; 6 Console.WriteLine(name); 7 Console.ReadKey(); 8 9 10 //可以讲string类型 看做是char类型的一个只读数组 11 string s = "abcdefg"; //"bbcdefg" 12 // s[0] = 'b';不能这样做 因为是只读的 13 //首先将字符串转换为char类型的数组 14 char[] chs = s.ToCharArray(); 15 chs[0] = 'b'; 16 //将字符数组转换为我们的字符串 17 s = new string(chs); 18 //既然可以将string看做char类型的只读数组,所以我可以通过下标去访问字符串中的某一个元素 19 Console.WriteLine(s[0]); 20 Console.WriteLine(s); 21 Console.ReadKey(); 22 } 23 }