c#查詢關鍵字之into的使用
引導語:c#借鑒了Delphi的一個特點,與COM(組件對象模型)是直接集成的,而且是微軟公司 .NET windows網絡框架的主角。以下是小編整理的c#查詢關鍵字之into的使用,歡迎參考閱讀!
可以使用 into 上下文關鍵字創建一個臨時標識符,以便將 group、join 或 select 子句的結果存儲到新的標識符中。此標識符本身可以是附加查詢命令的生成器。在 group 或 select 子句中使用新標識符的用法有時稱為“延續”。
示例
下面的示例演示使用 into 關鍵字來啟用臨時標識符 fruitGroup,該標識符具有推斷類型 IGrouping。通過使用該標識符,可以對每個組調用 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.
*/
僅當希望對每個組執行附加查詢操作時,才需要在 group 子句中使用 into。
【c#查詢關鍵字之into的使用】相關文章:
c#查詢關鍵字之group子句的使用02-24
c#關鍵字查詢之select 子句運用02-07
c#查詢關鍵字之join 子句運用方法07-01
c#查詢關鍵字from 子句的用法05-13
c#查詢關鍵字where 子句的運用06-01
c#運算符關鍵字is的使用02-03
c#檢測cpu使用率01-02
java的import關鍵字的使用05-04
c#中預處理指令#if的使用02-01