I'm trying to remove all records in a List<T>
matching a where condition. What I did find in linq is the RemoveAll()
method but it seems to only work by removing properties matching a condition instead of the complete row
in the list.
So I did try a remove all as suggested here in conjunction with a Where clause which causes an "argument null exception".
Question:
How can you RemoveAll list rows matching a condition using linq?
//Sort the list by the UpdatedTime time descending
//Remove all records in list that are older than today's date and status equal to BB. Then order the remaining records desc.
var cuttOff = DateTime.UtcNow.AddDays(-10);
List<Escalation> escHistorySorted = escHistory.RemoveAll.Where(x => x.UpdatedTime <= cuttOff && x.status == "BB").OrderByDescending(d => d.UpdatedTime).ToList();