©2009 Microsoft Corporation. All rights reserved.
C# Language Reference
into (C# Reference)

The into contextual keyword can be used to create a temporary identifier to store the results of a group [ http://msdn.microsoft.com/en-us/library/bb384063.aspx ] , join [ http://msdn.microsoft.com/en-us/library/bb311040.aspx ] or select [ http://msdn.microsoft.com/en-us/library/bb384087.aspx ] clause into a new identifier. This identifier can itself be a generator for additional query commands. When used in a group or select clause, the use of the new identifier is sometimes referred to as a continuation.

The following example shows the use of the into keyword to enable a temporary identifier fruitGroup which has an inferred type of IGrouping. By using the identifier, you can invoke the Count [ http://msdn.microsoft.com/en-us/library/system.linq.enumerable.count.aspx ] method on each group and select only those groups that contain two or more words.

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.
*/

The use of into in a group clause is only necessary when you want to perform additional query operations on each group. For more information, see group clause (C# Reference) [ http://msdn.microsoft.com/en-us/library/bb384063.aspx ] .

For an example of the use of into in a join clause, see join clause (C# Reference) [ http://msdn.microsoft.com/en-us/library/bb311040.aspx ] .

Concepts

LINQ Query Expressions (C# Programming Guide) [ http://msdn.microsoft.com/en-us/library/bb397676.aspx ]

Reference

group clause (C# Reference) [ http://msdn.microsoft.com/en-us/library/bb384063.aspx ]

Other Resources

Query Keywords (C# Reference) [ http://msdn.microsoft.com/en-us/library/bb310804.aspx ]
Tags: 
 
Community Content