C# - LINQ Extension: Append

By , 3/28/2016
(0 ratings)
This method appends an item to a sequence. To concatenate two sequences, you can use the existing Concat-method.

Required Namespace
/// <summary>
/// Appends an item to this sequence.
/// </summary>
/// <typeparam name="T">The type of the elements.</typeparam>
/// <param name="source">The source.</param>
/// <param name="newItem">The item to append.</param>
/// <returns>A new sequence with the items of <paramref name="source"/> and <paramref name="newItem"/>.</returns>
public static IEnumerable<T> Append<T>(this IEnumerable<T> source, T newItem)
    foreach (var item in source)
        yield return item;
    yield return newItem;
Tagged with LINQ, Append, List, Sequence, Extension.



Log in, to comment!