码迷,mamicode.com
首页 > 其他好文 > 详细

Linq 关键字

时间:2015-02-03 18:43:03      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:

from

var lowNums = from num in numbers
            where num < 5
           
select num;

numbers 是数据源,而 num 是范围变量。             请注意,这两个变量都是强类型

List<Student> students = new List<Student>
        {
           new Student {LastName="Omelchenko", Scores= new List<int> {97, 72, 81, 60}},
           new Student {LastName="O‘Donnell", Scores= new List<int> {75, 84, 91, 39}},
           new Student {LastName="Mortensen", Scores= new List<int> {88, 94, 65, 85}},
           new Student {LastName="Garcia", Scores= new List<int> {97, 89, 85, 82}},
           new Student {LastName="Beebe", Scores= new List<int> {35, 72, 91, 70}}
        };       

        // Use a compound from to access the inner sequence within each element.
        // Note the similarity to a nested foreach statement.
        var scoreQuery = from student in students
                         from score in student.Scores
                            where score > 90
                            select new { Last = student.LastName, score };
where

条件

where    子句用在查询表达式中,用于指定将在查询表达式中返回数据源中的哪些元素。            

它将一个布尔条件(“谓词”)应用于每个源元素(由范围变量引用),并返回满足指定条件的元素。  一个查询表达式可以包含多个 where 子句,一个子句可以包含多个谓词子表达式。

 

Linq 关键字

标签:

原文地址:http://www.cnblogs.com/handsomer/p/4270422.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!