Linq擴展函數(shù)有哪些

這篇文章主要為大家展示了“Linq擴展函數(shù)有哪些”,內(nèi)容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“Linq擴展函數(shù)有哪些”這篇文章吧。

創(chuàng)新互聯(lián)公司專注于瓜州企業(yè)網(wǎng)站建設(shè),自適應(yīng)網(wǎng)站建設(shè),商城系統(tǒng)網(wǎng)站開發(fā)。瓜州網(wǎng)站建設(shè)公司,為瓜州等地區(qū)提供建站服務(wù)。全流程按需定制制作,專業(yè)設(shè)計,全程項目跟蹤,創(chuàng)新互聯(lián)公司專業(yè)和態(tài)度為您提供的服務(wù)

首先介紹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<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 g.Length > 6  orderby g  select g).Count<string>();  // numb is the value 5.  Console.WriteLine("{0} items honor the LINQ query.", numb);  }

定義演示的實例

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

以上是“Linq擴展函數(shù)有哪些”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

分享文章:Linq擴展函數(shù)有哪些
標(biāo)題鏈接:http://www.muchs.cn/article44/ghgche.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供移動網(wǎng)站建設(shè)響應(yīng)式網(wǎng)站、手機網(wǎng)站建設(shè)、關(guān)鍵詞優(yōu)化、網(wǎng)站設(shè)計公司網(wǎng)站內(nèi)鏈

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站制作