如何在LINQ查询中指定范围变量的类型?

时间:2010-01-27 18:31:34

标签: c# winforms linq

如何在linq查询中指定范围变量的类型?

1 个答案:

答案 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());