Select section of list based on value of a enumeration
c#, linq
Solution
var lostResults = myResultList.Where(r => r.OutCome == enumResult.lose).ToList();
NOTE: Consider to have Pascal Case names for types and public members. And don't include prefixes in type names. E.g.
public enum Outcome
{
NoResult,
Win,
Lose
}
If you will need to filter results by other types of outcomes, then consider to use lookup:
var results = myResultList.ToLookup(r => r.OutCome);
Then getting results by their type will be easy:
var wonResults = results[enumResult.won];
Problem
I have a c# app. I have custom list of type result, shown below. The list is called 'myResultList'. ``` enumResult { noResult = 0, win = 1, lose = 2 } class Result { public enumResult OutCome {get; set;} public double Frequency {get;set;} public string GroupName {get; set;} public double TotalValue {get; set;} } ``` myResultList contains numerous elements. I wish to select all the elements where the Outcome equals lose into a new list. I believe LINQ is probably best for this task, correct me if I am wrong. How do I go about querying a list based on a enumeration?