Why does List.Find (and LINQ queries in a list) always return the first element of an enumeration when the list does not contain the element I'm looking for?
Scenario:
My listing:
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>();
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 return TestEnum.EnumOne. If I add TestEnum3 to the list, it will return correctly.
source
share