【发布时间】:2021-07-16 14:31:49
【问题描述】:
你好!
任务:3 人在 3 家不同的酒店下榻时被谋杀。谋杀不是在同一天发生的。您有来自每家酒店的 3 个列表,其中包含住在那里的人的姓名。如果您发现匹配的名称,请将其列为嫌疑人。
private void button1_Click(object sender, EventArgs e)
{
int index = 0;
for (int i = 0; i < n2; i++) //I have 3 different 'n's, n2 is the largest, that is why I use it here (n - listBox1; n2 - listBox2; n3 - listBox3)
{
if (Convert.ToString(listBox1.Text[i]) == Convert.ToString(listBox2.Text[i]) || Convert.ToString(listBox1.Text[i]) == Convert.ToString(listBox3.Text[i]) || Convert.ToString(listBox2.Text[i]) == Convert.ToString(listBox3.Text[i]))
{
listBox4.Items.Add(goldensheep[index]);
index++;
}
}
}
我有listBox1、listBox2和listBox3中列出的所有数据,目标是listBox4。
名称可以在数组中找到:“goldensheep”、“goldenbull”、“goldenostrich”,但我在这里只使用了“goldensheep”,因为我相信(d)这是唯一需要的。
当我点击 button1 时,我得到一个错误,但不幸的是我不知道为什么会发生这种情况。
提前致谢,祝你有美好的一天! :)
【问题讨论】:
-
请告诉我们您看到的确切错误是什么。
-
“索引指向数组边界之外”——或者类似的,我的 VS 不是英文的。
-
你能解释一下你使用
Convert.ToString()的意图吗? -
并非如此。我想我必须转换它们才能比较它们。