ConcatTo

static IEnumerable<T> ConcatTo<T>(IEnumerable<T> target, T element)
{
  return System.Linq.Concat(new[]{ element }, target);
}

or

static IEnumerable<T> ConcatTo<T>(IEnumerable<T> target, T element)
{
  yield return element;
  foreach(T e in target) yield return e;
}
Example:
IEnumerable<String> x = new[]{"foo", "bar"};
x = x.ConcatTo("bla");
Console.WriteLine(string.Join('--',x));

// returns bla--foo--bar

Description

Adds a single element at the beginning of an enumerator

Details

Double click on the code to select all.

 

;