Enumerable.ToList<TSource>(IEnumerable<TSource>) 메서드

정의

IEnumerable<T>에서 List<T>을 만듭니다.

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)

형식 매개 변수

TSource

source 요소의 형식입니다.

매개 변수

source
IEnumerable<TSource>

IEnumerable<T>을 만드는 데 사용할 List<T>입니다.

반환

List<TSource>

입력 시퀀스의 요소가 들어 있는 List<T>입니다.

예외

source이(가) null인 경우

예제

다음 코드 예제에서는 즉시 쿼리 평가를 강제 적용하고 쿼리 결과가 포함된 값을 반환 List<T> 하는 방법을 ToList 보여 줍니다.

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

설명

이 메서드는 ToList<TSource>(IEnumerable<TSource>) 즉시 쿼리를 강제로 계산하고 쿼리 결과가 포함된 값을 반환 List<T> 합니다. 쿼리 결과의 캐시된 복사본을 가져오기 위해 이 메서드를 쿼리에 추가할 수 있습니다.

ToArray에는 비슷한 동작이 있지만 .List<T>

적용 대상