我是编程新手。任何人都可以告诉我如何在lambda表达式中转换这个for循环
for (int num = 0; num < daysNew.Count(); num++)
{
for (int count = 0; count < daysOld.Count(); count++)
{
if (daysOld[count] == daysNew[num])
{
isValid = false;
break;
}
}
}
答案 0 :(得分:1)
这应该这样做:
bool isValid = !daysNew.Any(day => daysOld.Contains(day));
答案 1 :(得分:0)
使用List.Any()方法循环:
bool isValid = !daysNew.Any(day => daysOld.Contains(day));
或
bool isValid = !daysOld.Any(day => daysNew.Contains(day));
它将为“daysNew”中每个元素的每个元素检入“daysOld”