c# - What is an easy way to append or prepend a single value to an IEnumerable<T>? -


Let me know an IEnumerable (in this case, IEnumerable & lt; string [] & gt; / code>). To do this, I would like to combine first value with list :

:

  // Together headers and data simultaneously mobile & Lt; String []> Header = new list & lt; String []> {GetHeaders ()}; Var all = header Canakat (gatedata);  

Yuk is a better way? And how do you handle the case against adding value?

I've written custom extension methods to do this:

  Public stable IEnumerable & lt; T & gt; Endend & lt; T & gt; (This IEnumerable & lt; T & gt; source, T item) {foreach (source i) yield yield i; Yield returns item; } Public stable IEnumerable & lt; T & gt; Prepaid & lt; T & gt; (This IEnumerable & lt; T & gt; source, t item) {yield returns item; Foreign Currency (T in Source) yield returns i; }  

In your scenario, you will type:

  var all = GetData (). Prepare (GetHeaders ());  

As Chiltemp commented, it does not change the original collection in the right Linq fashion, it is a new IEnumerable & lt; T & gt; Generates .

Note: is an eager redundant logic test recommended for> source , but not shown for summarizing.


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -