【发布时间】:2011-04-11 00:52:15
【问题描述】:
我的 linq 查询如下:
var result = (from Customer cust in db select new { userNameList = cust.UserName }).ToList();
我想遍历列表中的每个值
我尝试使用 foreach 来完成此操作。太笨了,我想不通
我正在使用类似的东西
foreach (List<string> item in result)
{
if (item.ToString() == userName)
{
userExistsFlag = 1;
}
}
但是 .net 编译器只是吓坏了:
并给我这些错误
无法将类型“System.Collections.Generic.List”隐式转换为“System.Collections.Generic.List”
无法将类型“AnonymousType#1”转换为“System.Collections.Generic.List”
感谢期待
在所有这些实现中,哪一个是最高效且消耗资源更少的。 如果有人能为我澄清这一点,那就太好了。
【问题讨论】:
-
上面代码中的
db是什么类型的?