C#中对linq where查询的应用
来源:互联网 发布:js替换字符串中的数字 编辑:程序博客网 时间:2024/05/18 02:15
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace LINQ_WHERE{ /**//// <summary> /// LINQ where子句 /// </summary> class Program { static void Main(string[] args) { //1常见的where语句 List<GustInfo> gList = new List<GustInfo>() { new GustInfo(){ Name="DebugLZQ", Age=26,Tel="88888888"}, new GustInfo(){ Name="cnblogs",Age=6,Tel="666666"}, new GustInfo(){ Name="M&MSoft",Age=9,Tel="55555"} }; var query = from gust in gList where (gust.Name.Length > 7 || gust.Name.Substring(0, 1) == "M") && gust.Age > 9 select new { gust.Name, gust.Age }; foreach (var g in query) { Console.WriteLine("{0},{1}", g.Name, g.Age); } Console.ReadKey(false); //2.在where子句中使用自定义函数 var query2 = from GustInfo gust in gList where gust.Name.Length > 5 && Check(gust.Name) select gust; foreach (var g in query2) { Console.WriteLine("{0},{1},{2}", g.Name, g.Age, g.Tel); } Console.ReadKey(false); //3.动态谓词的筛选 //定义动态谓词数组,在实际开发中可以动态获得 string[] names = { "SB","XXX","***","@@@","一些敏感词"}; var query3 = from GustInfo guest in gList where !names.Contains(guest.Name) select guest; foreach (var q in query3) { Console.WriteLine("{0} 年龄:{1},电话:{2}",q.Name,q.Age,q.Tel ); } Console.ReadKey(false); } //自定义函数 static bool Check(string name) { if (name.Substring(0, 1) == "N") return false; return true; } }}
文章转载自: Linq中where查询 http://www.studyofnet.com/news/269.html
0 0
- C#中对linq where查询的应用
- Linq中where查询
- Linq中where查询
- Linq查询[Where]
- C#中linq 分组查询
- C#之LINQ基础 where中两个筛选条件的实例
- linq查询函数的应用
- C# 中 Linq查询结果的循环性能改进
- C#中 foreach,linq,delegate集合查询的性能比较
- LINQ 的select 和where 查询语句总结
- linq 的查询的学习 (google 中输入 101 linq) -- select的应用
- where条件对查询的影响
- C#之Linq、where()、FindAll()的区别
- C#中Linq查询基本操作
- 13.01.18 C# Linq 对查询的非重复元素排序
- C#使用linq to xml完成对XML文件的创建、增加、删除、修改、查询
- linq where 中两个条件
- C#利用Linq对DataTable过滤查询代码
- Fedora 安装Oracle 11gR2数据库
- line-height
- 如何查询公司有哪些股东?
- 不同局域网间的P2P通信技术
- Hibernate学习笔记
- C#中对linq where查询的应用
- 揭秘硬件
- JSON串:{"date":28,"day":3,"hours":5...转String 转Date 的相转方法
- Windows下的很多程序都有十分漂亮的菜单
- oracle jdk 1.6 下载链接
- php腾讯QQ 第三方登录 回调问题
- ZOJ 3740 —— Water Level(DP+线段树)
- UVa:10617 Again Palindrome
- 使用vs2010的基本设置