How to use IndexOf() method of List<object>

Viewed 104217

All the examples I see of using the IndexOf() method in List<T> are of basic string types. What I want to know is how to return the index of a list type that is an object, based on one of the object variables.

List<Employee> employeeList = new List<Employee>();
employeeList.Add(new Employee("First","Last",45.00));

I want to find the index where employeeList.LastName == "Something"

6 Answers

The answer is for those coming here to know why IndexOf() doesn't work.

Your class must override Equals method of object possessing the following declaration.

public override bool Equals(object obj)
Related