【发布时间】:2013-07-18 08:29:54
【问题描述】:
我有 2 个数组列表,我动态添加了它的值,如何比较它们并检查它们在循环中是否相等?像这样的:
ArrayList answers = new ArrayList();
ArrayList choosen = new ArrayList();
// in some method
{
answers.Add(qhm.Answer);
choosen.Add(tbox.Text);
}
然后在foreach循环中
private void button1_Click(object sender, RoutedEventArgs e) // Check Button
{
int c = 0;
foreach( //Compare two arraylist here)
{
if (answers == choosen) {
c++;
}
}
MessageBox.Show("You have answered : " + c + "questions correctly!");*/
}
我想要它
回答[1] = 选择[1]
答案[2] = 选择[2]
例如,存储在 answers 中的第一个数组等于存储在 choosen 中的第一个数组。
【问题讨论】:
-
ArrayList不再是一个好的选择。考虑使用List<string>。
标签: c# for-loop arraylist foreach