日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Linq基本語法概述

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

創(chuàng)新互聯(lián)公司專業(yè)為企業(yè)提供河南網(wǎng)站建設、河南做網(wǎng)站、河南網(wǎng)站設計、河南網(wǎng)站制作等企業(yè)網(wǎng)站建設、網(wǎng)頁設計與制作、河南企業(yè)網(wǎng)站模板建站服務,10年河南做網(wǎng)站經驗,不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡服務。

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()

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

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

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

也可以在兼容的數(shù)組類型上調用

 
 
 
  1. var makes = from c in myCars select c.Make;  
  2. Console.WriteLine("Distinct makes:");  
  3. foreach (var m in makes.Distinct())  
  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、生成新的數(shù)據(jù)類型(投影)

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

6、Reverse()

或者

 
 
 
  1. var subset = (from c in myCars select c).Reverse();  
  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兼容的對象的差集

 
 
 
  1. static void GetDiff()  
  2. {  
  3. List myCars = new List 
  4. { "Yugo", "Aztec", "BMW"};  
  5. List yourCars = new List 
  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基本語法


文章名稱:Linq基本語法概述
標題路徑:http://www.5511xx.com/article/djdihgg.html