查询关键字 - C# 参考

    子句 说明
    from 指定数据源和范围变量(类似于迭代变量)。
    where 基于由逻辑 AND 和 OR 运算符(&& )分隔的一个或多个布尔表达式筛选源元素。
    select 指定执行查询时,所返回序列中元素的类型和形状。
    group 根据指定的密钥值对查询结果分组。
    into 提供可作为对 join、group 或 select 子句结果引用的标识符。
    orderby 根据元素类型的默认比较器对查询结果进行升序或降序排序。
    join 基于两个指定匹配条件间的相等比较而联接两个数据源。
    let 引入范围变量,在查询表达式中存储子表达式结果。
    in join 子句中的上下文关键字。
    on join 子句中的上下文关键字。
    equals join 子句中的上下文关键字。
    by group 子句中的上下文关键字。
    ascending orderby 子句中的上下文关键字。
    descending orderby 子句中的上下文关键字。

    where 子句 - C# 参考 - C#

    1. class WhereSample
    2. {
    3. static void Main()
    4. {
    5. // Simple data source. Arrays support IEnumerable<T>.
    6. int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
    7. // Simple query with one predicate in where clause.
    8. var queryLowNums =
    9. from num in numbers
    10. where num < 5
    11. select num;
    12. // Execute the query.
    13. foreach (var s in queryLowNums)
    14. {
    15. Console.Write(s.ToString() + " ");
    16. }
    17. }
    18. }
    19. //Output: 4 1 3 2 0

    Enumerable.Where 方法 (System.Linq)

    1. List<string> fruits = new List<string> { "apple", "passionfruit", "banana", "mango", "orange", "blueberry", "grape", "strawberry" };
    2. IEnumerable<string> query = fruits.Where(fruit => fruit.Length < 6);
    3. foreach (string fruit in query)
    4. {
    5. Console.WriteLine(fruit);
    6. }
    7. /*
    8. This code produces the following output:
    9. apple
    10. mango
    11. grape
    12. */