- c#查詢(xún)關(guān)鍵字之group子句的使用 推薦度:
- 相關(guān)推薦
c#查詢(xún)關(guān)鍵字之into的使用
引導(dǎo)語(yǔ):c#借鑒了Delphi的一個(gè)特點(diǎn),與COM(組件對(duì)象模型)是直接集成的,而且是微軟公司 .NET windows網(wǎng)絡(luò)框架的主角。以下是小編整理的c#查詢(xún)關(guān)鍵字之into的使用,歡迎參考閱讀!
可以使用 into 上下文關(guān)鍵字創(chuàng)建一個(gè)臨時(shí)標(biāo)識(shí)符,以便將 group、join 或 select 子句的結(jié)果存儲(chǔ)到新的標(biāo)識(shí)符中。此標(biāo)識(shí)符本身可以是附加查詢(xún)命令的生成器。在 group 或 select 子句中使用新標(biāo)識(shí)符的用法有時(shí)稱(chēng)為“延續(xù)”。
示例
下面的示例演示使用 into 關(guān)鍵字來(lái)啟用臨時(shí)標(biāo)識(shí)符 fruitGroup,該標(biāo)識(shí)符具有推斷類(lèi)型 IGrouping。通過(guò)使用該標(biāo)識(shí)符,可以對(duì)每個(gè)組調(diào)用 Count 方法,并且僅選擇那些包含兩個(gè)或更多個(gè)單詞的組。
C#
class IntoSample1
{
static void Main()
{
// Create a data source.
string[] words = { "apples", "blueberries", "oranges", "bananas", "apricots"};
// Create the query.
var wordGroups1 =
from w in words
group w by w[0] into fruitGroup
where fruitGroup.Count() >= 2
select new { FirstLetter = fruitGroup.Key, Words = fruitGroup.Count() };
// Execute the query. Note that we only iterate over the groups,
// not the items in each group
foreach (var item in wordGroups1)
{
Console.WriteLine(" {0} has {1} elements.", item.FirstLetter, item.Words);
}
// Keep the console window open in debug mode
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
}
}
/* Output:
a has 2 elements.
b has 2 elements.
*/
僅當(dāng)希望對(duì)每個(gè)組執(zhí)行附加查詢(xún)操作時(shí),才需要在 group 子句中使用 into。
【c#查詢(xún)關(guān)鍵字之into的使用】相關(guān)文章:
c#查詢(xún)關(guān)鍵字之group子句的使用02-24
c#關(guān)鍵字查詢(xún)之select 子句運(yùn)用02-07
c#查詢(xún)關(guān)鍵字之join 子句運(yùn)用方法07-01
c#查詢(xún)關(guān)鍵字from 子句的用法05-13
c#查詢(xún)關(guān)鍵字where 子句的運(yùn)用06-01
c#檢測(cè)cpu使用率01-02
c#中預(yù)處理指令#if的使用02-01