Enumerable.ToList<TSource>(IEnumerable<TSource>) Yöntem

Tanım

bir içinden bir List<T> IEnumerable<T>oluşturur.

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static System::Collections::Generic::List<TSource> ^ ToList(System::Collections::Generic::IEnumerable<TSource> ^ source);
public static System.Collections.Generic.List<TSource> ToList<TSource> (this System.Collections.Generic.IEnumerable<TSource> source);
static member ToList : seq<'Source> -> System.Collections.Generic.List<'Source>
<Extension()>
Public Function ToList(Of TSource) (source As IEnumerable(Of TSource)) As List(Of TSource)

Tür Parametreleri

TSource

öğelerinin sourcetürü.

Parametreler

source
IEnumerable<TSource>

IEnumerable<T> kaynak oluşturmak List<T> için.

Döndürülenler

List<TSource>

List<T> Giriş dizisinden öğeleri içeren bir.

Özel durumlar

source, null değeridir.

Örnekler

Aşağıdaki kod örneği, sorgu değerlendirmesini zorlamak ve sorgu sonuçlarını içeren bir List<T> döndürmek için nasıl kullanılacağını ToList gösterir.

string[] fruits = { "apple", "passionfruit", "banana", "mango",
                      "orange", "blueberry", "grape", "strawberry" };

List<int> lengths = fruits.Select(fruit => fruit.Length).ToList();

foreach (int length in lengths)
{
    Console.WriteLine(length);
}

/*
 This code produces the following output:

 5
 12
 6
 5
 6
 9
 5
 10
*/
' Create an array of strings.
Dim fruits() As String =
{"apple", "passionfruit", "banana", "mango",
 "orange", "blueberry", "grape", "strawberry"}

' Project the length of each string and 
' put the length values into a List object.
Dim lengths As List(Of Integer) =
fruits _
.Select(Function(fruit) fruit.Length) _
.ToList()

' Display the results.
Dim output As New System.Text.StringBuilder
For Each length As Integer In lengths
    output.AppendLine(length)
Next
Console.WriteLine(output.ToString())

' This code produces the following output:
'
' 5
' 12
' 6
' 5
' 6
' 9
' 5
' 10

Açıklamalar

yöntemi anında ToList<TSource>(IEnumerable<TSource>) sorgu değerlendirmesini zorlar ve sorgu sonuçlarını içeren bir List<T> döndürür. Sorgu sonuçlarının önbelleğe alınmış bir kopyasını almak için bu yöntemi sorgunuza ekleyebilirsiniz.

ToArray benzer davranışa sahiptir, ancak yerine bir List<T>dizi döndürür.

Şunlara uygulanır