Enumerable.Prepend(IEnumerable<TSource>, TSource) Enumerable.Prepend(IEnumerable<TSource>, TSource) Enumerable.Prepend(IEnumerable<TSource>, TSource) Enumerable.Prepend(IEnumerable<TSource>, TSource) Method

정의

시퀀스의 시작 부분에 값을 추가합니다.Adds a value to the beginning of the sequence.

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

형식 매개 변수

TSource

source 요소의 형식입니다.The type of the elements of source.

매개 변수

source
IEnumerable<TSource>

값의 시퀀스입니다.A sequence of values.

element
TSource TSource TSource TSource

source 앞에 추가할 값입니다.The value to prepend to source.

반환

IEnumerable<TSource>

element로 시작하는 새 시퀀스입니다.A new sequence that begins with element.

예외

예제

다음 코드 예제에 사용 하는 방법을 보여 줍니다. Prepend 값 시퀀스의 시작 부분 앞에 있습니다.The following code example demonstrates how to use Prepend to prepend a value to the beginning of the sequence.

// Creating a list of numbers
List<int> numbers = new List<int> { 1, 2, 3, 4 };

// Trying to prepend any value of the same type
numbers.Prepend(0);

// It doesn't work because the original list has not been changed
Console.WriteLine(string.Join(", ", numbers));

// It works now because we are using a changed copy of the original list
Console.WriteLine(string.Join(", ", numbers.Prepend(0)));

// If you prefer, you can create a new list explicitly
List<int> newNumbers = numbers.Prepend(0).ToList();

// And then write to the console output
Console.WriteLine(string.Join(", ", newNumbers));

// This code produces the following output:
//
// 1, 2, 3, 4
// 0, 1, 2, 3, 4
// 0, 1, 2, 3, 4
' Creating a list of numbers
Dim numbers As New List(Of Integer)(New Integer() {1, 2, 3, 4})

' Trying to prepend any value of the same type
numbers.Prepend(0)

' It doesn't work because the original list has not been changed
Console.WriteLine(String.Join(", ", numbers))

' It works now because we are using a changed copy of the original list
Console.WriteLine(String.Join(", ", numbers.Prepend(0)))

' If you prefer, you can create a new list explicitly
Dim newNumbers As List(Of Integer) = numbers.Prepend(0).ToList

' And then write to the console output
Console.WriteLine(String.Join(", ", newNumbers))

' This code produces the following output:
'
' 1, 2, 3, 4
' 0, 1, 2, 3, 4
' 0, 1, 2, 3, 4

설명

참고

이 메서드는 컬렉션의 요소를 수정 하지 않습니다.This method does not modify the elements of the collection. 대신 새 요소를 사용 하 여 컬렉션의 복사본을 만듭니다.Instead, it creates a copy of the collection with the new element.

적용 대상