c#中有关数组的问题

来源:百度知道 编辑:UC知道 时间:2024/05/17 05:37:07
有4个textbox,一个数组string t[]
我现在想把这4个textbox里的内容保存到这个数组里面,应该怎么写

我手新手

string[] t = new string[4];
t[0] = textBox1.Text;
t[1] = textBox2.Text;
t[2] = textBox3.Text;
t[3] = textBox4.Text;
这是最简单而且最好记的方法

StringBuilder sb = new StringBuilder();
sb.Append(this.textBox1.Text);
sb.Append(this.textBox2.Text);
sb.Append(this.textBox3.Text);
sb.Append(this.textBox4.Text);
this.label1.Text = sb.ToString();

或者

string[] t = new string[4];
t[0] = this.textBox1.Text;
t[1] = this.textBox2.Text;
t[2] = this.textBox3.Text;
t[3] = this.textBox4.Text;
this.label1.Text = "";
for (int i = 0; i < t.Length; i++)
{
this.label1.Text += t[i];
}