荟萃馆

位置:首页 > 计算机 > C语言

c#查询关键字之into的使用

C语言1.29W

引导语: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。

标签:关键字