Merk
Tilgang til denne siden krever autorisasjon. Du kan prøve å logge på eller endre kataloger.
Tilgang til denne siden krever autorisasjon. Du kan prøve å endre kataloger.
Use the into contextual keyword to create a temporary identifier that stores the results of a group, join, or select clause. This identifier can act as a generator for additional query commands. When you use the new identifier in a group or select clause, it's sometimes called a continuation.
The C# language reference documents the most recently released version of the C# language. It also contains initial documentation for features in public previews for the upcoming language release.
The documentation identifies any feature first introduced in the last three versions of the language or in current public previews.
Tip
To find when a feature was first introduced in C#, consult the article on the C# language version history.
The following example shows how to use the into keyword to create a temporary identifier named fruitGroup, which has an inferred type of IGrouping. By using this identifier, you can call the Count method on each group and select only those groups that contain two or more words.
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($" {item.FirstLetter} has {item.Words} elements.");
}
}
}
/* Output:
a has 2 elements.
b has 2 elements.
*/
You only need to use into in a group clause when you want to perform additional query operations on each group. For more information, see group clause.
For an example of using into in a join clause, see join clause.