Having this enum :
public enum MyEnums
{
A = 1,
B = 2,
C = 3,
D = 4,
E = 5
}
If I create a list with some enum values from MyEnums for example this :
IEnumerable<MyEnums> myEnums = new(){ MyEnums.A, MyEnums.B, MyEnums.C };
How can I check that a int value is in this list?
query.Where(x => myEnums.Contains((int)x.MyValue));
The problem is that the name of 'x.MyValue' is not the same then the name in 'MyEnums' only the int value is the same.
If the collection of values has a property that is an
intvalue, then you can use the fact that anenumis actually anintunder the hood. It isn't clear exactly what you want, so here are a few possibilities (and I create a collection of simple objects to show):intvalues that are defined by theenum:The result is {1, 2}
enumvalues that are defined by theenumthat happen to be in the collection ofintvalues:The result is {A, B}
ExampleTypeobjects that have anintvalue for a property that is defined by theenum:The result is two
ExampleTypeobjects that haveMyValueproperty values that are valid values defined byMyEnum.