- c#查詢關(guān)鍵字之group子句的使用 推薦度:
- 相關(guān)推薦
c#查詢關(guān)鍵字之into的使用
引導(dǎo)語:c#借鑒了Delphi的一個特點,與COM(組件對象模型)是直接集成的,而且是微軟公司 .NET windows網(wǎng)絡(luò)框架的主角。以下是小編整理的c#查詢關(guān)鍵字之into的使用,歡迎參考閱讀!
可以使用 into 上下文關(guān)鍵字創(chuàng)建一個臨時標識符,以便將 group、join 或 select 子句的結(jié)果存儲到新的標識符中。此標識符本身可以是附加查詢命令的生成器。在 group 或 select 子句中使用新標識符的用法有時稱為“延續(xù)”。
示例
下面的示例演示使用 into 關(guān)鍵字來啟用臨時標識符 fruitGroup,該標識符具有推斷類型 IGrouping。通過使用該標識符,可以對每個組調(diào)用 Count 方法,并且僅選擇那些包含兩個或更多個單詞的組。
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.
*/
僅當希望對每個組執(zhí)行附加查詢操作時,才需要在 group 子句中使用 into。
【c#查詢關(guān)鍵字之into的使用】相關(guān)文章:
c#關(guān)鍵字查詢之select 子句運用02-07
c#查詢關(guān)鍵字之join 子句運用方法07-01
c#運算符關(guān)鍵字is的使用02-03
c#檢測cpu使用率01-02
c#中預(yù)處理指令#if的使用02-01