Given I have a IEnumerable (e) and a single value of T (t). What is the simplest way of doing:
IEnumerable<T> newCollection = t+e
At the moment I am doing:
ItemArray = Enumerable.Repeat<object>(t, 1).Concat(e);
which is rather unreadable, since I’am doing not real repeat here.
I also tried:
IEnumerable<T> newCollection = new List<object> { t}.Concat(e);
But this one creates an unecessary List object which also isn’t optimal.
Does anyone have a better idea?
Jon Skeet’s answer is the most semantically valuable. However, if you still want a way to do it inline, you can use an implicitly-typed array: