先来看一段简单的C#代码:
private void button3_Click(object sender, EventArgs e){char[] a = new char[6] { 'h', 'e', 'L', 'O', '\0', '\0' }; // 少赋值一个元素都会报错string b = new string(a);string result = String.Format("b = {0}, b.Length = {1}", b, b.Length);MessageBox.Show(result);}
看下运行结果: