Use Where
to filter the sequence.
var tlistFiltered = tlist.Where(item => item.suburb == "brisbane")
LINQ expressions such as Where return IEnumerable<T>
. I usually take the result with var, but you can use ToList()
to project the result into a list. Just change what you need to do with the list later.
List<Temp> tlistFiltered = tlist .Where(item => item.suburb == "brisbane") .ToList()
Please note that with the above, you do not need to highlight a new list. The Where
and ToList()
methods return a new sequence that you only need to capture using the link.
source share