Say I have a class that looks something like this:
class SomeClass {
int m_member;
public int Member {
get { return m_member; }
set { m_member = value; }
}
}
And somewhere else, I have a list of type List<SomeClass> list
.
If I want to search the list for a particular instance of the class, I can just do
int index = list.IndexOf(someInstance);
But if I want to search the list by Member, I have to do this:
int index = -1;
for (int i = 0; i < list.Count; i++) {
if (list[i].Member == someMember) {
index = i;
break;
}
}
Is there a better way to do this?