LINQ Append Method in C#:

The LINQ Append Method in C# is used to append a value to the end of the sequence. This method does not modify the elements of the sequence. Instead, it creates a copy of the sequence with the new appended element. If you go to the definition of the Append Method, then you will see the following signature.

  1. TSource: The data type of the elements contained in the sequence.
Parameters:
  1. IEnumerable<TSource> source: A sequence of values.
  2. TSource element: The value to append at the end of the sequence.
Returns:
  1. IEnumerable<TSource>: A new sequence that ends with the element.

Exceptions: When the source is null, it will throw ArgumentNullException.

Note: This method is supported by Framework 4.7.1 or later.

Example:

The following example shows how to use the Append Method to append a value to the end of the sequence. The following example is self-explained. So, please go through the comment lines.

In the next article, I am going to discuss the LINQ Prepend Method in C# with examples. Here, in this article, I try to explain the LINQ Append Method with an example.

Leave a Comment