How come List.Find (and LINQ-queries on the list as well) always return the first enum element when the list does not contain the element I am searching for?
Scenario:
My enum:
public enum TestEnum
{
EnumOne,
EnumTwo,
EnumThree
}
My test:
var TestEnum1 = TestEnum.EnumOne;
var TestEnum2 = TestEnum.EnumTwo;
var TestEnum3 = TestEnum.EnumThree;
List<TestEnum> testEnumList = new List<TestEnum>();//{ TestEnum1, TestEnum2 };
var selectedWithLinq = (from c in testEnumList where c.Equals(TestEnum3) select c).FirstOrDefault();
var selectedWithListFind = testEnumList.Find(myEnum => TestEnum3.Equals(myEnum)));
Both selectedWithLinq and selectedWithListFind in this case returns TestEnum.EnumOne. If I add TestEnum3 to the list, it will return correctly.