C# 2008 LINQ 基础- LINQ 语法 Posted on 2008-02-22 13:56 sunrack 阅读(614) 评论(1) 编辑收藏网摘所属分类: C# 2008 一、 LINQ 查询符列表 Query Operators Meaning in Life from, in Used to define the backbone for any LINQ expression, which allows you to extract a subset of data from a fitting container. where Used to define a restriction for which items to extract from a container. select Used to select a sequence from the container. join, on, equals, into Performs joins based on specified key. Remember, these “ joins ” do not need to have anything to do with data ina relational database. orderby, ascending, descending Allows the resulting subset to be ordered in ascending or descending order. group, by Yields a subset with data grouped bya specified value. 另外还有一些没有操作符号,而是以扩展函数(泛型函数)的方式提供的函数: 用不同方式产生结果集: Reverse<>(), ToArray<>(), ToList<>() 集合操作: Distinct<>(), Union<>(), Intersect<>() 统计函数: Count<>(), Sum<>(), Min<>(), Max<>() 二、使用 Enumerable 获取 Counts 为了使用这些 Enumerable 扩展函数, 一般把 LINQ 查询表达式用括号括起来, 先转换为 IEnumerable<T> 兼容的对象。 static void GetCount() { string [] currentVideoGames ={ "Morrowind" , "BioShock" , "Half Life 2: Episode 1" , "The Darkness" , "Daxter" , "System Shock 2" }; // Get count from the query. int numb = (from g in currentVideoGames where >6 orderby g select g).Count< string >(); // numb is the value 5. ( "{0} items honor the LINQ query." , numb); } 三、定义演示的实例 class Car
C# 2008 LINQ基础- LINQ语法 来自淘豆网www.taodocs.com转载请标明出处.