I am developing a small project and I thought I could try something I don’t know so I can learn something new.
I have a collection of Messages, called msgs. I would like to filter only the unread ones and then set it to “read”.
To do that, I called the Where method with this lambda expression, I imagine I would get a list of all messages which are unread. Now I would like to set the value to “Read” (assigning ‘T’ to the MessageRead property). Is there a way to do that using lambda expressions?
I got to this code, but the “All” method is not what I am loking for, I just found out that it checks if all the elements in the list match this condition.
msgs.Where(message => message.MessageRead == 'F').All(message => message.MessageRead = 'T');
Thanks a lot,
Oscar
What you are after is a ForEach extension method, see discussions here: LINQ equivalent of foreach for IEnumerable<T>