Is there a more elegant solution for adding an item to an IEnumerable than this
myNewIEnumerable = myIEnumerable.Concat ( Enumerable.Repeat (item, 1) );
?
Some context:
public void printStrings (IEnumerable<string> myStrings) {
Console.WriteLine ("The beginning.");
foreach (var s in myStrings) Console.WriteLine (s);
Console.WriteLine ("The end.");
}
...
var result = someMethodDeliveringAnIEnumerableOfStrings ();
printStrings (result.Concat ( Enumerable.Repeat ("finished", 1) ) );
Maybe the easiest way to append a single element to an
IEnumerable<T>is to use thisAsIEnumerableextension (although Eric Lippert advises against creating extension for objects):or use this
Append<T>extension: https://stackoverflow.com/a/3645715/284240