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

前端 未结 6 1682
遥遥无期
遥遥无期 2020-12-29 01:08

All the examples I see of using the IndexOf() method in List are of basic string types. What I want to know is how to return the index of

6条回答
  •  借酒劲吻你
    2020-12-29 01:57

    public int FindIndex(Predicate match);
    

    Using lambdas:

    employeeList.FindIndex(r => r.LastName.Equals("Something"));
    

    Note:

    // Returns:
    //     The zero-based index of the first occurrence of an element
    //     that matches the conditions defined by match, if found; 
    //     otherwise, –1.
    

提交回复
热议问题