Appending an element to a collection using LINQ

Posted by SRKX on Stack Overflow See other posts from Stack Overflow or by SRKX
Published on 2011-11-18T09:42:41Z Indexed on 2011/11/18 9:51 UTC
Read the original article Hit count: 242

Filed under:
|
|

I am trying to process some list with a functional approach in C#.

The idea is that I have a collection of Tuple<T,double> and I want to change the Item 2 of some element T.

The functional way to do so, as data is immutable, is to take the list, filter for all elements where the element is different from the one to change, and the append a new tuple with the new values.

My problem is that I do not know how to append the element at the end. I would like to do:

public List<Tuple<T,double>> Replace(List<Tuple<T,double>> collection, T term,double value)
{
   return collection.Where(x=>!x.Item1.Equals(term)).Append(Tuple.Create(term,value));
}

But there is no Append method. Is there something else?

© Stack Overflow or respective owner

Related posts about c#

Related posts about LINQ