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

前端 未结 6 1680
遥遥无期
遥遥无期 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 02:02

    int index = employeeList.FindIndex(employee => employee.LastName.Equals(somename, StringComparison.Ordinal));
    

    Edit: Without lambdas for C# 2.0 (the original doesn't use LINQ or any .NET 3+ features, just the lambda syntax in C# 3.0):

    int index = employeeList.FindIndex(
        delegate(Employee employee)
        {
            return employee.LastName.Equals(somename, StringComparison.Ordinal);
        });
    

提交回复
热议问题