糯米文學吧

位置:首頁 > 計算機 > C語言

c#查詢關鍵字之into的使用

C語言1.14W

引導語:c#借鑑了Delphi的一個特點,與COM(組件對象模型)是直接集成的,而且是微軟公司 windows網絡框架的主角。以下是小編整理的c#查詢關鍵字之into的`使用,歡迎參考閲讀!

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 t() >= 2

select new { FirstLetter = , Words = t() };

// Execute the query. Note that we only iterate over the groups,

// not the items in each group

foreach (var item in wordGroups1)

{

eLine(" {0} has {1} elements.", tLetter, s);

}

// Keep the console window open in debug mode

eLine("Press any key to exit.");

Key();

}

}

/* Output:

a has 2 elements.

b has 2 elements.

*/

僅當希望對每個組執行附加查詢操作時,才需要在 group 子句中使用 into。

標籤:關鍵字