扩展方法配合Lambda表示达,可以方便我们进行数据的查询,看个代码吧:
IEnumerable<string> x=new List<string> {"1","zzl","good"}; //为对象赋值
foreach (var info in x.ForUser("zzl")) //从其中筛选zzl这个字符
{
Response.Write(info);
}
public static class filter
{
public static IEnumerable<string> ForUser(this IEnumerable<string> qry, string userName)
{
return from a in qry
where
a.Contains(userName.ToLower())
select a;
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)