延迟操作符:凡是IEnumerable<T>或IOrderedEnumerable<T>类型的值的操作符都属于延迟操作符。

1.限定操作符

Where

作用:用于将筛选出来的元素放到一个序列中

原型

    public static IEnumerable<T> Where<T>(
        this IEnumerable<T> source,
        Func<T,bool> predicate);

 

    public static IEnumerable<T> Where<T>(
        this IEnumerable<T> source,
        Func<T,int,bool> predicate);

 

例子

    static void Main(string[] args)
    {
        string[] items = { "csharp", "vb", "java", "cpp", "python","php","c++" };

        var result = items.Where<string>(c => c.StartsWith("c"));
        //显示查询结果
         foreach (var item in result)
        {
            Console.WriteLine(item);
        }

        Console.Read();
    }

结果

Linq学习笔记--延迟操作符(限定操作符) 

       

    static void Main(string[] args)
    {
        string[] items = { "csharp", "vb", "java", "cpp", "python","php","c++" };

        var result = items.Where<string>((c,i) => (i & 1) == 1);
        //显示查询结果
         foreach (var item in result)
        {
            Console.WriteLine(item);
        }

        Console.Read();
    }

 

结果

Linq学习笔记--延迟操作符(限定操作符)

相关文章:

  • 2021-09-13
  • 2021-10-21
  • 2022-01-06
  • 2021-12-24
  • 2021-09-23
  • 2021-07-08
  • 2021-10-21
  • 2021-10-10
猜你喜欢
  • 2021-10-11
  • 2022-03-07
  • 2021-11-24
  • 2021-09-22
  • 2021-10-01
  • 2021-08-23
  • 2021-06-23
相关资源
相似解决方案