我有一个动态创建的CheckBoxList. 在此CheckBoxList,我有一个foreach用于验证用户输入的嵌套循环。用户输入他或她的电子邮件地址。一旦用户单击提交,CheckBoxList就会创建。如果用户的电子邮件与某个主题的订阅相匹配,则会选中该主题旁边的复选框。我遇到的问题是将原始外部foreach与嵌套的foreach.
int i = 0;
foreach (Topic topic in result)
{
string topicName = topic.TopicArn.ToString().Split(':').Last();
ListItem li = new ListItem(topicName, topic.TopicArn);
checkBoxList1.Items.Add(li);
foreach (Subscription subscription in subs) // where topic equals current
// topic in original foreach?
{
if (txtEmail.Text == subscription.Endpoint)
checkBoxList1.Items[i].Selected = true;
}
i++;
}
我在想我也许可以使用 LINQ 向nestedforeach 循环添加一个条件,但我还不能把它全部放在一起。