Enumerable.Append<TSource>(IEnumerable<TSource>, TSource) メソッド
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
シーケンスの末尾に値を追加します。
public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
static System::Collections::Generic::IEnumerable<TSource> ^ Append(System::Collections::Generic::IEnumerable<TSource> ^ source, TSource element);
C#
public static System.Collections.Generic.IEnumerable<TSource> Append<TSource> (this System.Collections.Generic.IEnumerable<TSource> source, TSource element);
static member Append : seq<'Source> * 'Source -> seq<'Source>
<Extension()>
Public Function Append(Of TSource) (source As IEnumerable(Of TSource), element As TSource) As IEnumerable(Of TSource)
- TSource
source
の要素の型。
- source
- IEnumerable<TSource>
値のシーケンス。
- element
- TSource
source
に追加する値。
IEnumerable<TSource>
element
で終わる新しいシーケンス。
source
が null
です。
次のコード例では、 を使用 Append してシーケンスの末尾に値を追加する方法を示します。
C#
// Creating a list of numbers
List<int> numbers = new List<int> { 1, 2, 3, 4 };
// Trying to append any value of the same type
numbers.Append(5);
// 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.Append(5)));
// If you prefer, you can create a new list explicitly
List<int> newNumbers = numbers.Append(5).ToList();
// And then write to the console output
Console.WriteLine(string.Join(", ", newNumbers));
// This code produces the following output:
//
// 1, 2, 3, 4
// 1, 2, 3, 4, 5
// 1, 2, 3, 4, 5
' Creating a list of numbers
Dim numbers As New List(Of Integer)(New Integer() {1, 2, 3, 4})
' Trying to append any value of the same type
numbers.Append(5)
' 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.Append(5)))
' If you prefer, you can create a new list explicitly
Dim newNumbers As List(Of Integer) = numbers.Append(5).ToList
' And then write to the console output
Console.WriteLine(String.Join(", ", newNumbers))
' This code produces the following output:
'
' 1, 2, 3, 4
' 1, 2, 3, 4, 5
' 1, 2, 3, 4, 5
注意
このメソッドは、コレクションの要素を変更しません。 代わりに、新しい要素を使用してコレクションのコピーを作成します。
製品 | バージョン |
---|---|
.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 | 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.6, 2.0, 2.1 |
GitHub で Microsoft と共同作業する
このコンテンツのソースは GitHub にあります。そこで、issue や pull request を作成および確認することもできます。 詳細については、共同作成者ガイドを参照してください。
.NET に関するフィードバック
.NET はオープンソース プロジェクトです。 フィードバックを提供するにはリンクを選択します。