Enumerable.ToList<TSource>(IEnumerable<TSource>) 메서드
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
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<T>입니다.
source
이(가) null
인 경우
다음 코드 예제에서는 를 사용하여 ToList 즉시 쿼리 평가를 강제 적용하고 쿼리 결과가 포함된 을 List<T> 반환하는 방법을 보여 줍니다.
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>.
제품 | 버전 |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |
.NET 피드백
.NET은(는) 오픈 소스 프로젝트입니다. 다음 링크를 선택하여 피드백을 제공해 주세요.