这篇文章主要介绍“LINQ嵌套怎么使用”,在日常操作中,相信很多人在LINQ嵌套怎么使用问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”LINQ嵌套怎么使用”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
LINQ嵌套的实例:
using System; using System.Linq; class P { static void Main() { var customer = new[]{new {PKId="001",Name="admin",Pwd="123456",Group="001"}, new {PKId="002",Name="user",Pwd="user",Group="003"}, new {PKId="003",Name="geust",Pwd="guest",Group="004"}, new {PKId="004",Name="aa",Pwd="123456",Group="002"}, new {PKId="005",Name="bb",Pwd="123456",Group="002"}, new {PKId="006",Name="cc",Pwd="123456",Group="002"}, }; var groups = new[] { new { PKId = "001", depict = "***权限" }, new {PKId="002",depict="管理员"}, new {PKId="003",depict="发布信息"}, new {PKId="004",depict="只有浏览权限"} }; var data = from word2 in groups where word2.depict == "管理员" //LINQ嵌套的问题所在 select new { quanxian = word2.depict, Name = from word in customer where word.Group==word.PKId select word }; var first = data.First(); Console.WriteLine("{0}, {1}", first.quanxian, first.Name); } } //下面是输出: 管理员, System.Linq.Enumerable+WhereArrayIterator`1[<>f__AnonymousType0`4[System .String, System.String,System.String,System.String]]
关于LINQ嵌套问题的分析:
看到没?Name的值是个其名IEnumerator.
正确的LINQ嵌套写法应该是:
var data = from word2 in groups where word2.depict == &
到此,关于“LINQ嵌套怎么使用”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注编程网网站,小编会继续努力为大家带来更多实用的文章!