我有一个测试项目,将4个字符串放在列表中,但似乎无法做到这一点。我正在尝试使用for和foreach循环在2个文本框中查看我的列表。把字符串放在列表<string>和输出
private void button1_Click(object sender, EventArgs e)
{
List<string[]> testList2 = new List<string[]>();
string[] text = { textBox1.Text, textBox2.Text, textBox3.Text, textBox4.Text };
testList2.Add(text);
textBox5.Text = testList2.Count.ToString();
foreach (string[] list1 in testList2)
{
foreach (string list2 in list1)
{
textBox6.Text = list2.ToString();
}
}
string temp = testList2.ToString();
for (int i = 0; i < testList2.Count; i++)
{
for (int j = 0; j < i; j++)
{
textBox7.Text = testList2[j].ToString();
}
}
}
你的问题是什么? – 2013-02-18 02:00:24
不显示列表中所有字符串的循环。下面的答案适用于foreach,但是for循环没有显示任何输出。 – 2013-02-18 02:24:17