LINQ 学习笔记8 Kevin

Chapter 4 延迟操作


1.引用命名空间

using System.Linq;

using System.Collections;

using System.Collections.Generic;

using System.Data.Linq;

2.Where方法

WHere 方法的作用是根据查询条件过滤结果。

where 方法有两个原型:

第一个:

public static IEnumerable<T> Where<T>(

this IEnumerable<T> source,

Func<T,bool> predicate);

 该原型的作用是通过输入一个可以进行Enumberable的序列,返回那些满足委托条件返回true的元素。

第二个:

Public static IEnumberalbe<T> source,Func<T,int,bool> predicate);

第二个原型与第一个原型是一样的,除了它接比第一个多接受一个int类型的参数。这个是参数是输入参数中的Index。

Index是以0为开始的,所以的第一个参数的Index是0,最后一个参数的Index是参数个数减1.

Exception:

如果参数中有参数为null,将会抛出一个ArgumentNullException异常。

Select


select 操作符用来创建一种类型的结果集,并非一定要和输入的元素类型相同。

第一种原型:

Public static IEnumberable<S> Select<T,S>(

  this IEnumberable<T> source,

     Func<T,S> selector

);

原文地址:https://www.cnblogs.com/kfx2007/p/2706394.html