数组的元素在指定位置插入一个数字
发现百度也百不到的问题,有些人答非所问导致学习风气一团乱套,所以写一点基础需要的同志可以参考
private void button1_Click(object sender, EventArgs e) { int [] num=new int[6]; num[0] = 0; num[1] = 1; num[2] = 2; num[3] = 3; num[4] = 4; string res = string.Empty; for (int i = 0; i < num.Length; i++) { res += num[i] + ","; } this.label1.Text = "插入前:"+res; string res1 = string.Empty; for (int i = 0; i < num.Length; i++) { res += num[i]; if (i == 2) { for (int j = num.Length-1; j > 2; j--) { if (j < 6) { num[j] = num[j - 1]; } } num[2] = int.Parse(this.textBox1.Text); break; } } for (int i = 0; i < num.Length; i++) { res1 += num[i].ToString()+","; } this.label2.Text = "插入后:" + res1; }
积累小的知识,才能成就大的智慧,希望网上少一些复制多一些原创有用的答案