如何在linq查询中指定范围变量的类型?
答案 0 :(得分:16)
只需用变量本身声明它:
var query = from string text in collection
where text.Length > 5
select text.ToUpper();
这将转换为:
var query = collection.Cast<string>()
.Where(text => text.Length > 5)
.Select(text => text.ToUpper());