Let's say I have
[Flags]
public enum MyEnum
{
ValueZero = 1,
ValueOne = 2,
ValueTwo = 4
}
public class MyClass
{
public string Property { get; set; }
public MyEnum EnumValue { get; set; }
}
I'd want to be able to use GroupBy
on a List<MyClass>
to group by enums without considering that it is a flag enum.
When I use GroupBy
(example at the end of the question), the groupings are made with the aggregated enums like this
//Grouping Values
ValueZero | ValueOne : myClass1, myClass2
ValueOne | ValueTwo : myClass3, myClass4
I'm looking to get the following (using the GroupBy method because it is more performant than using Where
3 times)
//Grouping Values
ValueZero : myClass1, myClass2
ValueOne : myClass1, myClass2, myClass3, myClass4
ValueTwo : myClass4
I thought using this would work :
var list = new List<MyClass>();
var groupedList = list.GroupBy(c => c.EnumValue);