成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

Linq基本語法概述

開發 后端
這里介紹Linq基本語法,包括names隱式類型的變量、使用Enumerable.Distinct<T>()、調用Enumberalbe擴展函數和Reverse<T>()等方面。

在向大家詳細介紹Linq基本語法之前,首先讓大家了解下調用Enumberalbe擴展函數,然后全面介紹Linq基本語法。

Linq基本語法

  1. var result = from item in container orderby value ascending/descending select item; 

1、獲取全部記錄

  1. var allCars = from c in myCars select c; 

2、只獲取字段名稱

  1. var names = from c in myCars select c.PetName; 

這里names就是隱式類型的變量。

3、使用Enumerable.Distinct<T>()

  1. var makes = (from c in myCars select c.Make).Distinct<string>(); 

4、即可以在定義的時候調用Enumberalbe擴展函數

  1. var names = from c in myCars select c.PetName;  
  2. foreach (var n in names)  
  3. {  
  4. Console.WriteLine("Name: {0}", n);  

也可以在兼容的數組類型上調用

  1. var makes = from c in myCars select c.Make;  
  2. Console.WriteLine("Distinct makes:");  
  3. foreach (var m in makes.Distinct<string>())  
  4. {  
  5. Console.WriteLine("Make: {0}", m);  

 

  1. // Now get only the BMWs.  
  2. var onlyBMWs = from c in myCars where c.Make == "BMW" select c; 

 

  1. // Get BMWs going at least 100 mph.  
  2. var onlyFastBMWs = from c in myCars  
  3. where c.Make == "BMW" && c.Speed >= 100  
  4. select c; 

5、生成新的數據類型(投影)

  1. var makesColors = from c in myCars select new {c.Make, c.Color}; 

6、Reverse<T>()

或者

  1. var subset = (from c in myCars select c).Reverse<Car>();  
  2. foreach (Car c in subset)  
  3. {  
  4. Console.WriteLine("{0} is going {1} MPH", c.PetName, c.Speed);  

7、排序

默認是ascending

  1. // Order all the cars by PetName.  
  2. var subset = from c in myCars orderby c.PetName select c;  
  3. // Now find the cars that are going less than 55 mph,  
  4. // and order by descending PetName  
  5. subset = from c in myCars  
  6. where c.Speed > 55 orderby c.PetName descending select c; 

默認順序時也可以明確指明

  1. var subset = from c in myCars  
  2. orderby c.PetName ascending select c; 

8、Enumerable.Except()
兩個IEnumerable<T>兼容的對象的差集

  1. static void GetDiff()  
  2. {  
  3. List<string> myCars = new List<String> 
  4. { "Yugo", "Aztec", "BMW"};  
  5. List<string> yourCars = new List<String> 
  6. { "BMW", "Saab", "Aztec" };  
  7. var carDiff =(from c in myCars select c)  
  8. .Except(from c2 in yourCars select c2);  
  9. Console.WriteLine("Here is what you don't have, but I do:");  
  10. foreach (string s in carDiff)  
  11. Console.WriteLine(s); // Prints Yugo.  

以上介紹Linq基本語法

【編輯推薦】

  1. Linq to SQL學習經驗
  2. Linq隱式類型化局部變量
  3. Linq匿名類型簡單概述
  4. Linq Lambda表達式剖析
  5. Linq對象初始值淺談
責任編輯:佚名 來源: IT168
相關推薦

2009-09-10 13:42:47

Linq UserIn

2009-09-10 11:10:21

Linq Librar

2009-09-08 11:25:42

Linq foreac

2009-09-18 16:07:10

Linq Where操

2009-09-18 16:20:36

LINQ基礎

2009-09-08 16:08:44

Linq使用order

2009-09-10 16:28:17

LINQ查詢

2009-09-11 12:13:40

LINQ to SQL

2009-09-18 13:44:38

LINQ設計模式

2009-09-16 17:21:53

LINQ遍歷

2009-09-14 15:15:45

LINQ技術

2009-09-09 16:53:53

LINQ查詢語法

2009-09-09 16:01:21

Linq實體繼承使用

2009-09-09 16:07:16

Linq實體關系

2009-09-11 10:38:03

LINQ體系結構

2009-09-15 11:29:04

LINQ to SQL

2009-09-17 11:35:40

Linq匿名類型

2009-09-18 16:12:22

LINQ TO SQL

2009-09-11 10:16:07

Linq匿名類型

2009-09-15 13:37:24

Linq To Sql
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 精品国产一区二区在线 | 国产小网站 | 在线播放中文字幕 | 亚洲欧洲成人 | 成人中文字幕在线 | 亚洲视频在线观看 | 激情五月婷婷 | 欧美激情在线精品一区二区三区 | 一区二区三区四区免费视频 | 欧美高清性xxxxhdvideosex | 国产1区| 日韩无 | 一区二区三区成人 | 国产在线精品免费 | 欧美在线观看一区二区 | 日本三级在线 | 欧美黄页 | 欧美成人精品在线 | 日韩一区二区三区av | a级大毛片 | 一区免费 | 欧美精品久久久久 | 久久成人免费 | 亚洲国内精品 | 成人不卡| 国产激情在线观看视频 | 国产欧美一区二区久久性色99 | 国产做a爱免费视频 | 久久精品av| 日本特黄a级高清免费大片 特黄色一级毛片 | 亚洲色综合| www.天堂av.com | 亚洲人成免费 | 在线观看av免费 | 一区二区三区视频在线观看 | 在线观看视频91 | 亚洲精品68久久久一区 | 亚洲精品www | 韩日一区 | 91 在线 | 一区二区三区中文字幕 |