C#字符串数组的奇怪现象
大家看下这段代码:
代码
1 private void button1_Click(object sender, EventArgs e)
2 {
3 int[] issa = new int[3] { 1, 2, 3,4 }; //直接报错
4 int[] issb = new int[2];
5 for (int i = 0; i < 5; i++) //编译报错 越界
6 {
7 issb[i] = i;
8 }
9 string[] sssc = new string[3] { "a","b","c"};
10 string[] sssd = new string[0];
11 textBox2.Text = sssd.Length.ToString(); //长度自动变为0
12 string xx = "a;sa;sfe;wef;ewtwe;wetwe;wetwegdf;fdh;y45;rt4;yrt;reyrey;rgterg;rg;";
13
14 sssd = xx.Split(';'); //一切正常 ??
15 textBox3.Text = sssd.Length.ToString(); //长度自动变为15
16 string[] ssse = new string[20];
17
18 sssd.CopyTo(ssse, 0);
19
20 foreach (string str in ssse)
21 {
22 textBox1.Text = textBox1.Text + " | " + str;
23 }
24 }
2 {
3 int[] issa = new int[3] { 1, 2, 3,4 }; //直接报错
4 int[] issb = new int[2];
5 for (int i = 0; i < 5; i++) //编译报错 越界
6 {
7 issb[i] = i;
8 }
9 string[] sssc = new string[3] { "a","b","c"};
10 string[] sssd = new string[0];
11 textBox2.Text = sssd.Length.ToString(); //长度自动变为0
12 string xx = "a;sa;sfe;wef;ewtwe;wetwe;wetwegdf;fdh;y45;rt4;yrt;reyrey;rgterg;rg;";
13
14 sssd = xx.Split(';'); //一切正常 ??
15 textBox3.Text = sssd.Length.ToString(); //长度自动变为15
16 string[] ssse = new string[20];
17
18 sssd.CopyTo(ssse, 0);
19
20 foreach (string str in ssse)
21 {
22 textBox1.Text = textBox1.Text + " | " + str;
23 }
24 }
字符串数组sssd居然可以如上使用而不出错,不知为何?