I am trying to use the “List.Find” method to find a match with an element in my class. Here is an example…
class MyClass
{
String item1;
String item2;
}
List<MyClass> myClassList = new List<MyClass>();
// I am trying to find all instances of "MyClass" in the list "myClassList"
// where the element "item1" is equal to "abc"
// myClassList.Find(item => .item1 == "abc"); ?????
Anyway, I hope that explains a bit better. I am confused about the last part, so my question is: How can I use List.Find to find matches of an element in a list of classes.
Thanks and please let me know if I’m not being clear.
Your example is almost there. You should probably be using the
FindAllmethod:Or, if you prefer your results to be typed as
IEnumerable<T>rather thanList<T>, you can use LINQ’sWheremethod: