If i = {1,2} no problem.
If iId = 3 (or anything else) why does .First() crash.
public class C { public int ID, public string nam }
int i = 3;
C c = new List<C>;
c.Add(new C{ID = 1, nam="hello" });
c.Add(new C{ID = 2, nam=world" });
C r = c.First(e => e.ID.Equals(i));
The exception is:
InvalidOperationException was unhandled by user code
Sequence contains no matching element
I would think the least the expression would have to do is return null.
Instead it crashed.
That makes no sense to me.
A returned null would make sense to me.
What do you do to work around this? What is your best practice?