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

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

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Linq擴展函數(shù)淺談

XX有很多值得學(xué)習(xí)的地方,這里我們主要介紹Linq擴展函數(shù),包括介紹Linq擴展函數(shù)Enumerable獲取Counts等方面。

本文首先介紹Linq擴展函數(shù)(泛型函數(shù))的方式提供的函數(shù):
◆用不同方式產(chǎn)生結(jié)果集: Reverse<>(), ToArray<>(), ToList<>()
◆集合操作: Distinct<>(), Union<>(), Intersect<>()
◆統(tǒng)計函數(shù): Count<>(), Sum<>(), Min<>(), Max<>()

Linq擴展函數(shù)Enumerable獲取Counts

為了使用這些Enumerable擴展函數(shù),一般把LINQ查詢表達式用括號括起來,先轉(zhuǎn)換為IEnumerable兼容的對象。

 
 
 
  1. static void GetCount()  
  2. {  
  3. string[] currentVideoGames = {"Morrowind", "BioShock",  
  4. "Half Life 2: Episode 1", "The Darkness",  
  5. "Daxter", "System Shock 2"};  
  6. // Get count from the query.  
  7. int numb = (from g in currentVideoGames  
  8. where g.Length > 6  
  9. orderby g  
  10. select g).Count();  
  11. // numb is the value 5.  
  12. Console.WriteLine("{0} items honor the LINQ query.", numb);  

定義演示的實例

 
 
 
  1. class Car  
  2. {  
  3. public string PetName = string.Empty;  
  4. public string Color = string.Empty;  
  5. public int Speed;  
  6. public string Make = string.Empty;  
  7. public override string ToString()  
  8. {  
  9. return string.Format("Make={0}, Color={1}, Speed={2}, PetName={3}",  
  10. Make, Color, Speed, PetName);  
  11. }  
 
 
 
  1. static void Main(string[] args)  
  2. {  
  3. Console.WriteLine("***** Fun with Query Expressions *****"n");  
  4. // This array will be the basis of our testing  
  5. Car[] myCars = new [] {  
  6. new Car{ PetName = "Henry", Color = "Silver", Speed = 100, Make = "BMW"},  
  7. new Car{ PetName = "Daisy", Color = "Tan", Speed = 90, Make = "BMW"},  
  8. new Car{ PetName = "Mary", Color = "Black", Speed = 55, Make = "VW"},  
  9. new Car{ PetName = "Clunker", Color = "Rust", Speed = 5, Make = "Yugo"},  
  10.  
  11. new Car{ PetName = "Hank", Color = "Tan", Speed = 0, Make = "Ford"},  
  12. new Car{ PetName = "Sven", Color = "White", Speed = 90, Make = "Ford"},  
  13. new Car{ PetName = "Mary", Color = "Black", Speed = 55, Make = "VW"},  
  14. new Car{ PetName = "Zippy", Color = "Yellow", Speed = 55, Make = "VW"},  
  15. new Car{ PetName = "Melvin", Color = "White", Speed = 43, Make = "Ford"}  
  16. };  
  17. // We will call various methods here!  
  18. Console.ReadLine();  

分享標(biāo)題:Linq擴展函數(shù)淺談
瀏覽地址:http://www.5511xx.com/article/cohioos.html