當前位置:才華齋>計算機>C語言>

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

C語言 閱讀(1.18W)

引導語: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。