into (C# リファレンス)

into コンテキスト キーワードを使用すると、groupjoin、または select 句の結果を新しい識別子に格納するための一時識別子を作成できます。 この識別子自体が、追加のクエリ コマンドのジェネレーターになります。 group 句または select 句で使用する場合、この新しい識別子の用法は、継続と呼ばれることがあります。

使用例

into キーワードを使用して、推論された型 IGrouping を持つ一時識別子 fruitGroup を使用可能にする方法の例を次に示します。 識別子を使用することにより、各グループに対して Count メソッドを呼び出し、2 つ以上の単語を含むグループのみを選択できます。

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

into を group 句で使用する必要があるのは、各グループに対して追加のクエリ操作を実行する場合だけです。 詳細については、「group 句 (C# リファレンス)」を参照してください。

join 句での into の使用例については、「join 句 (C# リファレンス)」を参照してください。

参照

参照

group 句 (C# リファレンス)

概念

LINQ クエリ式 (C# プログラミング ガイド)

その他の技術情報

クエリ キーワード (C# リファレンス)