Enumerable.SelectMany メソッド

定義

シーケンスの各要素を IEnumerable<T> に投影し、結果のシーケンスを 1 つのシーケンスにフラット化します。

オーバーロード

名前 説明
SelectMany<TSource,TCollection,TResult>(IEnumerable<TSource>, Func<TSource,IEnumerable<TCollection>>, Func<TSource,TCollection,TResult>)

シーケンスの各要素を IEnumerable<T>に投影し、結果のシーケンスを 1 つのシーケンスにフラット化し、その中の各要素に対して結果セレクター関数を呼び出します。

SelectMany<TSource,TCollection,TResult>(IEnumerable<TSource>, Func<TSource,Int32,IEnumerable<TCollection>>, Func<TSource,TCollection,TResult>)

シーケンスの各要素を IEnumerable<T>に投影し、結果のシーケンスを 1 つのシーケンスにフラット化し、その中の各要素に対して結果セレクター関数を呼び出します。 各ソース要素のインデックスは、その要素の中間投影形式で使用されます。

SelectMany<TSource,TResult>(IEnumerable<TSource>, Func<TSource,IEnumerable<TResult>>)

シーケンスの各要素を IEnumerable<T> に投影し、結果のシーケンスを 1 つのシーケンスにフラット化します。

SelectMany<TSource,TResult>(IEnumerable<TSource>, Func<TSource,Int32,IEnumerable<TResult>>)

シーケンスの各要素を IEnumerable<T>に投影し、結果のシーケンスを 1 つのシーケンスにフラット化します。 各ソース要素のインデックスは、その要素の投影形式で使用されます。

SelectMany<TSource,TCollection,TResult>(IEnumerable<TSource>, Func<TSource,IEnumerable<TCollection>>, Func<TSource,TCollection,TResult>)

シーケンスの各要素を IEnumerable<T>に投影し、結果のシーケンスを 1 つのシーケンスにフラット化し、その中の各要素に対して結果セレクター関数を呼び出します。

public:
generic <typename TSource, typename TCollection, typename TResult>
[System::Runtime::CompilerServices::Extension]
 static System::Collections::Generic::IEnumerable<TResult> ^ SelectMany(System::Collections::Generic::IEnumerable<TSource> ^ source, Func<TSource, System::Collections::Generic::IEnumerable<TCollection> ^> ^ collectionSelector, Func<TSource, TCollection, TResult> ^ resultSelector);
public static System.Collections.Generic.IEnumerable<TResult> SelectMany<TSource,TCollection,TResult>(this System.Collections.Generic.IEnumerable<TSource> source, Func<TSource,System.Collections.Generic.IEnumerable<TCollection>> collectionSelector, Func<TSource,TCollection,TResult> resultSelector);
static member SelectMany : seq<'Source> * Func<'Source, seq<'Collection>> * Func<'Source, 'Collection, 'Result> -> seq<'Result>
<Extension()>
Public Function SelectMany(Of TSource, TCollection, TResult) (source As IEnumerable(Of TSource), collectionSelector As Func(Of TSource, IEnumerable(Of TCollection)), resultSelector As Func(Of TSource, TCollection, TResult)) As IEnumerable(Of TResult)

型パラメーター

TSource

sourceの要素の型。

TCollection

collectionSelectorによって収集される中間要素の型。

TResult

結果のシーケンスの要素の型。

パラメーター

source
IEnumerable<TSource>

投影する値のシーケンス。

collectionSelector
Func<TSource,IEnumerable<TCollection>>

入力シーケンスの各要素に適用する変換関数。

resultSelector
Func<TSource,TCollection,TResult>

中間シーケンスの各要素に適用する変換関数。

返品

IEnumerable<TResult>

sourceの各要素でcollectionSelector一対多変換関数を呼び出し、それらの各シーケンス要素とそれに対応するソース要素を結果要素にマッピングした結果を要素とするIEnumerable<T>

例外

source または collectionSelector または resultSelectornull

次のコード例では、 SelectMany<TSource,TCollection,TResult>(IEnumerable<TSource>, Func<TSource,IEnumerable<TCollection>>, Func<TSource,TCollection,TResult>) を使用して配列に対して一対多プロジェクションを実行し、結果セレクター関数を使用して、ソース シーケンスの対応する各要素を Selectの最後の呼び出しのスコープ内に保持する方法を示します。

class PetOwner
{
    public string Name { get; set; }
    public List<string> Pets { get; set; }
}

public static void SelectManyEx3()
{
    PetOwner[] petOwners =
        { new PetOwner { Name="Higa",
              Pets = new List<string>{ "Scruffy", "Sam" } },
          new PetOwner { Name="Ashkenazi",
              Pets = new List<string>{ "Walker", "Sugar" } },
          new PetOwner { Name="Price",
              Pets = new List<string>{ "Scratches", "Diesel" } },
          new PetOwner { Name="Hines",
              Pets = new List<string>{ "Dusty" } } };

    // Project the pet owner's name and the pet's name.
    var query =
        petOwners
        .SelectMany(petOwner => petOwner.Pets, (petOwner, petName) => new { petOwner, petName })
        .Where(ownerAndPet => ownerAndPet.petName.StartsWith("S"))
        .Select(ownerAndPet =>
                new
                {
                    Owner = ownerAndPet.petOwner.Name,
                    Pet = ownerAndPet.petName
                }
        );

    // Print the results.
    foreach (var obj in query)
    {
        Console.WriteLine(obj);
    }
}

// This code produces the following output:
//
// {Owner=Higa, Pet=Scruffy}
// {Owner=Higa, Pet=Sam}
// {Owner=Ashkenazi, Pet=Sugar}
// {Owner=Price, Pet=Scratches}
Structure PetOwner
    Public Name As String
    Public Pets() As String
End Structure

Sub SelectManyEx3()
    ' Create an array of PetOwner objects.
    Dim petOwners() As PetOwner =
{New PetOwner With
 {.Name = "Higa", .Pets = New String() {"Scruffy", "Sam"}},
 New PetOwner With
 {.Name = "Ashkenazi", .Pets = New String() {"Walker", "Sugar"}},
 New PetOwner With
 {.Name = "Price", .Pets = New String() {"Scratches", "Diesel"}},
 New PetOwner With
 {.Name = "Hines", .Pets = New String() {"Dusty"}}}

    ' Project an anonymous type that consists of
    ' the owner's name and the pet's name (string).
    Dim query =
petOwners _
.SelectMany(
    Function(petOwner) petOwner.Pets,
    Function(petOwner, petName) New With {petOwner, petName}) _
.Where(Function(ownerAndPet) ownerAndPet.petName.StartsWith("S")) _
.Select(Function(ownerAndPet) _
       New With {.Owner = ownerAndPet.petOwner.Name,
                 .Pet = ownerAndPet.petName
       })

    Dim output As New System.Text.StringBuilder
    For Each obj In query
        output.AppendLine(String.Format("Owner={0}, Pet={1}", obj.Owner, obj.Pet))
    Next

    ' Display the output.
    Console.WriteLine(output.ToString())
End Sub

' This code produces the following output:
'
' Owner=Higa, Pet=Scruffy
' Owner=Higa, Pet=Sam
' Owner=Ashkenazi, Pet=Sugar
' Owner=Price, Pet=Scratches

注釈

このメソッドは、遅延実行を使用して実装されます。 即時戻り値は、アクションの実行に必要なすべての情報を格納するオブジェクトです。 このメソッドで表されるクエリは、GetEnumerator メソッドを直接呼び出すか、C# で foreach を使用するか、Visual Basic で For Each を使用して列挙されるまで実行されません。

SelectMany<TSource,TCollection,TResult>(IEnumerable<TSource>, Func<TSource,IEnumerable<TCollection>>, Func<TSource,TCollection,TResult>) メソッドは、SelectMany<TSource,TCollection,TResult>(IEnumerable<TSource>, Func<TSource,IEnumerable<TCollection>>, Func<TSource,TCollection,TResult>)の呼び出し後に発生するクエリ ロジックのスコープ内にsourceの要素を保持する必要がある場合に便利です。 コード例については、「例」セクションを参照してください。 型 TSource のオブジェクトと TCollection型のオブジェクトの間に双方向の関係がある場合、つまり、型 TCollection オブジェクトが生成した TSource オブジェクトを取得するプロパティを提供する場合、この SelectMany<TSource,TCollection,TResult>(IEnumerable<TSource>, Func<TSource,IEnumerable<TCollection>>, Func<TSource,TCollection,TResult>)のオーバーロードは必要ありません。 代わりに、SelectMany<TSource,TResult>(IEnumerable<TSource>, Func<TSource,IEnumerable<TResult>>)を使用して、TCollection オブジェクトを介してTSource オブジェクトに戻ることができます。

クエリ式構文では、最初の句の後の各 from 句 (C#) または From 句 (Visual Basic) は、SelectMany の呼び出しに変換されます。

こちらもご覧ください

適用対象

SelectMany<TSource,TCollection,TResult>(IEnumerable<TSource>, Func<TSource,Int32,IEnumerable<TCollection>>, Func<TSource,TCollection,TResult>)

シーケンスの各要素を IEnumerable<T>に投影し、結果のシーケンスを 1 つのシーケンスにフラット化し、その中の各要素に対して結果セレクター関数を呼び出します。 各ソース要素のインデックスは、その要素の中間投影形式で使用されます。

public:
generic <typename TSource, typename TCollection, typename TResult>
[System::Runtime::CompilerServices::Extension]
 static System::Collections::Generic::IEnumerable<TResult> ^ SelectMany(System::Collections::Generic::IEnumerable<TSource> ^ source, Func<TSource, int, System::Collections::Generic::IEnumerable<TCollection> ^> ^ collectionSelector, Func<TSource, TCollection, TResult> ^ resultSelector);
public static System.Collections.Generic.IEnumerable<TResult> SelectMany<TSource,TCollection,TResult>(this System.Collections.Generic.IEnumerable<TSource> source, Func<TSource,int,System.Collections.Generic.IEnumerable<TCollection>> collectionSelector, Func<TSource,TCollection,TResult> resultSelector);
static member SelectMany : seq<'Source> * Func<'Source, int, seq<'Collection>> * Func<'Source, 'Collection, 'Result> -> seq<'Result>
<Extension()>
Public Function SelectMany(Of TSource, TCollection, TResult) (source As IEnumerable(Of TSource), collectionSelector As Func(Of TSource, Integer, IEnumerable(Of TCollection)), resultSelector As Func(Of TSource, TCollection, TResult)) As IEnumerable(Of TResult)

型パラメーター

TSource

sourceの要素の型。

TCollection

collectionSelectorによって収集される中間要素の型。

TResult

結果のシーケンスの要素の型。

パラメーター

source
IEnumerable<TSource>

投影する値のシーケンス。

collectionSelector
Func<TSource,Int32,IEnumerable<TCollection>>

各ソース要素に適用する変換関数。関数の 2 番目のパラメーターは、ソース要素のインデックスを表します。

resultSelector
Func<TSource,TCollection,TResult>

中間シーケンスの各要素に適用する変換関数。

返品

IEnumerable<TResult>

sourceの各要素でcollectionSelector一対多変換関数を呼び出し、それらの各シーケンス要素とそれに対応するソース要素を結果要素にマッピングした結果を要素とするIEnumerable<T>

例外

source または collectionSelector または resultSelectornull

注釈

このメソッドは、遅延実行を使用して実装されます。 即時戻り値は、アクションの実行に必要なすべての情報を格納するオブジェクトです。 このメソッドで表されるクエリは、GetEnumerator メソッドを直接呼び出すか、C# で foreach を使用するか、Visual Basic で For Each を使用して列挙されるまで実行されません。

SelectMany<TSource,TCollection,TResult>(IEnumerable<TSource>, Func<TSource,Int32,IEnumerable<TCollection>>, Func<TSource,TCollection,TResult>) メソッドは、SelectMany<TSource,TCollection,TResult>(IEnumerable<TSource>, Func<TSource,Int32,IEnumerable<TCollection>>, Func<TSource,TCollection,TResult>)の呼び出し後に発生するクエリ ロジックのスコープ内にsourceの要素を保持する必要がある場合に便利です。 コード例については、「例」セクションを参照してください。 型 TSource のオブジェクトと TCollection型のオブジェクトの間に双方向の関係がある場合、つまり、型 TCollection オブジェクトが生成した TSource オブジェクトを取得するプロパティを提供する場合、この SelectMany<TSource,TCollection,TResult>(IEnumerable<TSource>, Func<TSource,Int32,IEnumerable<TCollection>>, Func<TSource,TCollection,TResult>)のオーバーロードは必要ありません。 代わりに、SelectMany<TSource,TResult>(IEnumerable<TSource>, Func<TSource,Int32,IEnumerable<TResult>>)を使用して、TCollection オブジェクトを介してTSource オブジェクトに戻ることができます。

適用対象

SelectMany<TSource,TResult>(IEnumerable<TSource>, Func<TSource,IEnumerable<TResult>>)

シーケンスの各要素を IEnumerable<T> に投影し、結果のシーケンスを 1 つのシーケンスにフラット化します。

public:
generic <typename TSource, typename TResult>
[System::Runtime::CompilerServices::Extension]
 static System::Collections::Generic::IEnumerable<TResult> ^ SelectMany(System::Collections::Generic::IEnumerable<TSource> ^ source, Func<TSource, System::Collections::Generic::IEnumerable<TResult> ^> ^ selector);
public static System.Collections.Generic.IEnumerable<TResult> SelectMany<TSource,TResult>(this System.Collections.Generic.IEnumerable<TSource> source, Func<TSource,System.Collections.Generic.IEnumerable<TResult>> selector);
static member SelectMany : seq<'Source> * Func<'Source, seq<'Result>> -> seq<'Result>
<Extension()>
Public Function SelectMany(Of TSource, TResult) (source As IEnumerable(Of TSource), selector As Func(Of TSource, IEnumerable(Of TResult))) As IEnumerable(Of TResult)

型パラメーター

TSource

sourceの要素の型。

TResult

selectorによって返されるシーケンスの要素の型。

パラメーター

source
IEnumerable<TSource>

投影する値のシーケンス。

selector
Func<TSource,IEnumerable<TResult>>

各要素に適用する変換関数。

返品

IEnumerable<TResult>

入力シーケンスの各要素で一対多変換関数を呼び出した結果の要素を持つ IEnumerable<T>

例外

source または selectornull

次のコード例では、 SelectMany<TSource,TResult>(IEnumerable<TSource>, Func<TSource,IEnumerable<TResult>>) を使用して配列に対して一対多プロジェクションを実行する方法を示します。

class PetOwner
{
    public string Name { get; set; }
    public List<String> Pets { get; set; }
}

public static void SelectManyEx1()
{
    PetOwner[] petOwners =
        { new PetOwner { Name="Higa, Sidney",
              Pets = new List<string>{ "Scruffy", "Sam" } },
          new PetOwner { Name="Ashkenazi, Ronen",
              Pets = new List<string>{ "Walker", "Sugar" } },
          new PetOwner { Name="Price, Vernette",
              Pets = new List<string>{ "Scratches", "Diesel" } } };

    // Query using SelectMany().
    IEnumerable<string> query1 = petOwners.SelectMany(petOwner => petOwner.Pets);

    Console.WriteLine("Using SelectMany():");

    // Only one foreach loop is required to iterate
    // through the results since it is a
    // one-dimensional collection.
    foreach (string pet in query1)
    {
        Console.WriteLine(pet);
    }

    // This code shows how to use Select()
    // instead of SelectMany().
    IEnumerable<List<String>> query2 =
        petOwners.Select(petOwner => petOwner.Pets);

    Console.WriteLine("\nUsing Select():");

    // Notice that two foreach loops are required to
    // iterate through the results
    // because the query returns a collection of arrays.
    foreach (List<String> petList in query2)
    {
        foreach (string pet in petList)
        {
            Console.WriteLine(pet);
        }
        Console.WriteLine();
    }
}

/*
 This code produces the following output:

 Using SelectMany():
 Scruffy
 Sam
 Walker
 Sugar
 Scratches
 Diesel

 Using Select():
 Scruffy
 Sam

 Walker
 Sugar

 Scratches
 Diesel
*/
Structure PetOwner
    Public Name As String
    Public Pets() As String
End Structure

Sub SelectManyEx1()
    ' Create an array of PetOwner objects.
    Dim petOwners() As PetOwner =
{New PetOwner With
 {.Name = "Higa, Sidney", .Pets = New String() {"Scruffy", "Sam"}},
 New PetOwner With
 {.Name = "Ashkenazi, Ronen", .Pets = New String() {"Walker", "Sugar"}},
 New PetOwner With
 {.Name = "Price, Vernette", .Pets = New String() {"Scratches", "Diesel"}}}

    ' Call SelectMany() to gather all pets into a "flat" sequence.
    Dim query1 As IEnumerable(Of String) =
petOwners.SelectMany(Function(petOwner) petOwner.Pets)

    Dim output As New System.Text.StringBuilder("Using SelectMany():" & vbCrLf)
    ' Only one foreach loop is required to iterate through
    ' the results because it is a one-dimensional collection.
    For Each pet As String In query1
        output.AppendLine(pet)
    Next

    ' This code demonstrates how to use Select() instead
    ' of SelectMany() to get the same result.
    Dim query2 As IEnumerable(Of String()) =
petOwners.Select(Function(petOwner) petOwner.Pets)
    output.AppendLine(vbCrLf & "Using Select():")
    ' Notice that two foreach loops are required to iterate through
    ' the results because the query returns a collection of arrays.
    For Each petArray() As String In query2
        For Each pet As String In petArray
            output.AppendLine(pet)
        Next
    Next

    ' Display the output.
    Console.WriteLine(output.ToString())
End Sub

' This code produces the following output:
'
' Using SelectMany():
' Scruffy
' Sam
' Walker
' Sugar
' Scratches
' Diesel
'
' Using Select():
' Scruffy
' Sam
' Walker
' Sugar
' Scratches
' Diesel

注釈

このメソッドは、遅延実行を使用して実装されます。 即時戻り値は、アクションの実行に必要なすべての情報を格納するオブジェクトです。 このメソッドで表されるクエリは、GetEnumerator メソッドを直接呼び出すか、C# で foreach を使用するか、Visual Basic で For Each を使用して列挙されるまで実行されません。

SelectMany<TSource,TResult>(IEnumerable<TSource>, Func<TSource,IEnumerable<TResult>>) メソッドは、入力シーケンスを列挙し、変換関数を使用して各要素をIEnumerable<T>にマップした後、そのような各IEnumerable<T> オブジェクトの要素を列挙して生成します。 つまり、 sourceの各要素に対して selector が呼び出され、値のシーケンスが返されます。 SelectMany<TSource,TResult>(IEnumerable<TSource>, Func<TSource,IEnumerable<TResult>>) 次に、コレクションのこの 2 次元コレクションを 1 次元の IEnumerable<T> にフラット化し、それを返します。 たとえば、クエリで SelectMany<TSource,TResult>(IEnumerable<TSource>, Func<TSource,IEnumerable<TResult>>) を使用してデータベース内の各顧客の注文 (Order 型) を取得する場合、結果は C# では IEnumerable<Order> 型、Visual Basic では IEnumerable(Of Order) になります。 代わりに、クエリで Select を使用して注文を取得する場合、注文のコレクションは結合されず、結果は C# では IEnumerable<List<Order>> 型、Visual Basic では IEnumerable(Of List(Of Order)) 型になります。

クエリ式構文では、最初の句の後の各 from 句 (C#) または From 句 (Visual Basic) は、SelectMany の呼び出しに変換されます。

こちらもご覧ください

適用対象

SelectMany<TSource,TResult>(IEnumerable<TSource>, Func<TSource,Int32,IEnumerable<TResult>>)

シーケンスの各要素を IEnumerable<T>に投影し、結果のシーケンスを 1 つのシーケンスにフラット化します。 各ソース要素のインデックスは、その要素の投影形式で使用されます。

public:
generic <typename TSource, typename TResult>
[System::Runtime::CompilerServices::Extension]
 static System::Collections::Generic::IEnumerable<TResult> ^ SelectMany(System::Collections::Generic::IEnumerable<TSource> ^ source, Func<TSource, int, System::Collections::Generic::IEnumerable<TResult> ^> ^ selector);
public static System.Collections.Generic.IEnumerable<TResult> SelectMany<TSource,TResult>(this System.Collections.Generic.IEnumerable<TSource> source, Func<TSource,int,System.Collections.Generic.IEnumerable<TResult>> selector);
static member SelectMany : seq<'Source> * Func<'Source, int, seq<'Result>> -> seq<'Result>
<Extension()>
Public Function SelectMany(Of TSource, TResult) (source As IEnumerable(Of TSource), selector As Func(Of TSource, Integer, IEnumerable(Of TResult))) As IEnumerable(Of TResult)

型パラメーター

TSource

sourceの要素の型。

TResult

selectorによって返されるシーケンスの要素の型。

パラメーター

source
IEnumerable<TSource>

投影する値のシーケンス。

selector
Func<TSource,Int32,IEnumerable<TResult>>

各ソース要素に適用する変換関数。関数の 2 番目のパラメーターは、ソース要素のインデックスを表します。

返品

IEnumerable<TResult>

入力シーケンスの各要素で一対多変換関数を呼び出した結果の要素を持つ IEnumerable<T>

例外

source または selectornull

次のコード例では、 SelectMany<TSource,TResult>(IEnumerable<TSource>, Func<TSource,Int32,IEnumerable<TResult>>) を使用して配列に対して一対多プロジェクションを実行し、各外部要素のインデックスを使用する方法を示します。

class PetOwner
{
    public string Name { get; set; }
    public List<string> Pets { get; set; }
}

public static void SelectManyEx2()
{
    PetOwner[] petOwners =
        { new PetOwner { Name="Higa, Sidney",
              Pets = new List<string>{ "Scruffy", "Sam" } },
          new PetOwner { Name="Ashkenazi, Ronen",
              Pets = new List<string>{ "Walker", "Sugar" } },
          new PetOwner { Name="Price, Vernette",
              Pets = new List<string>{ "Scratches", "Diesel" } },
          new PetOwner { Name="Hines, Patrick",
              Pets = new List<string>{ "Dusty" } } };

    // Project the items in the array by appending the index
    // of each PetOwner to each pet's name in that petOwner's
    // array of pets.
    IEnumerable<string> query =
        petOwners.SelectMany((petOwner, index) =>
                                 petOwner.Pets.Select(pet => index + pet));

    foreach (string pet in query)
    {
        Console.WriteLine(pet);
    }
}

// This code produces the following output:
//
// 0Scruffy
// 0Sam
// 1Walker
// 1Sugar
// 2Scratches
// 2Diesel
// 3Dusty
Structure PetOwner
    Public Name As String
    Public Pets() As String
End Structure

Sub SelectManyEx2()
    ' Create an array of PetOwner objects.
    Dim petOwners() As PetOwner =
{New PetOwner With
 {.Name = "Higa, Sidney", .Pets = New String() {"Scruffy", "Sam"}},
 New PetOwner With
 {.Name = "Ashkenazi, Ronen", .Pets = New String() {"Walker", "Sugar"}},
 New PetOwner With
 {.Name = "Price, Vernette", .Pets = New String() {"Scratches", "Diesel"}},
 New PetOwner With
 {.Name = "Hines, Patrick", .Pets = New String() {"Dusty"}}}

    ' Project the items in the array by appending the index
    ' of each PetOwner to each pet's name in that petOwner's
    ' array of pets.
    Dim query As IEnumerable(Of String) =
petOwners.SelectMany(Function(petOwner, index) _
                         petOwner.Pets.Select(Function(pet) _
                                                  index.ToString() + pet))

    Dim output As New System.Text.StringBuilder
    For Each pet As String In query
        output.AppendLine(pet)
    Next

    ' Display the output.
    Console.WriteLine(output.ToString())
End Sub

注釈

このメソッドは、遅延実行を使用して実装されます。 即時戻り値は、アクションの実行に必要なすべての情報を格納するオブジェクトです。 このメソッドで表されるクエリは、GetEnumerator メソッドを直接呼び出すか、C# で foreach を使用するか、Visual Basic で For Each を使用して列挙されるまで実行されません。

SelectMany<TSource,TResult>(IEnumerable<TSource>, Func<TSource,Int32,IEnumerable<TResult>>) メソッドは、入力シーケンスを列挙し、変換関数を使用して各要素をIEnumerable<T>にマップした後、そのような各IEnumerable<T> オブジェクトの要素を列挙して生成します。 つまり、 sourceの各要素に対して selector が呼び出され、値のシーケンスが返されます。 SelectMany<TSource,TResult>(IEnumerable<TSource>, Func<TSource,Int32,IEnumerable<TResult>>) 次に、コレクションのこの 2 次元コレクションを 1 次元の IEnumerable<T> にフラット化し、それを返します。 たとえば、クエリで SelectMany<TSource,TResult>(IEnumerable<TSource>, Func<TSource,Int32,IEnumerable<TResult>>) を使用してデータベース内の各顧客の注文 (Order 型) を取得する場合、結果は C# では IEnumerable<Order> 型、Visual Basic では IEnumerable(Of Order) になります。 代わりに、クエリで Select を使用して注文を取得する場合、注文のコレクションは結合されず、結果は C# では IEnumerable<List<Order>> 型、Visual Basic では IEnumerable(Of List(Of Order)) 型になります。

selectorする最初の引数は、処理する要素を表します。 selectorする 2 番目の引数は、ソース シーケンス内の要素の 0 から始まるインデックスを表します。 これは、要素が既知の順序にあり、たとえば、特定のインデックスにある要素を使用して何かを行う場合に便利です。 また、1 つ以上の要素のインデックスを取得する場合にも便利です。

適用対象