List<'T>.FindIndex Method (Int32, Int32, Predicate<'T>)
Searches for an element that matches the conditions defined by the specified predicate, and returns the zero-based index of the first occurrence within the range of elements in the List<'T> that starts at the specified index and contains the specified number of elements.
Assembly: mscorlib (in mscorlib.dll)
The zero-based starting index of the search.
The number of elements in the section to search.
Return ValueType: System.Int32
The zero-based index of the first occurrence of an element that matches the conditions defined by match, if found; otherwise, –1.
The List<'T> is searched forward starting at startIndex and ending at startIndex plus count minus 1, if count is greater than 0.
The Predicate<'T> is a delegate to a method that returns true if the object passed to it matches the conditions defined in the delegate. The elements of the current List<'T> are individually passed to the Predicate<'T> delegate. The delegate has the signature:
This method performs a linear search; therefore, this method is an O(n) operation, where n is count.
The following example defines an Employee class with two fields, Name and Id. It also defines an EmployeeSearch class with a single method, StartsWith, that indicates whether the Employee.Name field starts with a specified substring that is supplied to the EmployeeSearch class constructor. Note the signature of this method
corresponds to the signature of the delegate that can be passed to the FindIndex method. The example instantiates a List<Employee> object, adds a number of Employee objets to it, and then calls the method twice to search the entire collection (that is, the members from index 0 to index Count - 1). The first time, it searches for the first Employee object whose Name field begins with "J"; the second time, it searches for the first Employee object whose Name field begins with "Ju".
Available since 8
Available since 2.0
Portable Class Library
Supported in: portable .NET platforms
Windows Phone Silverlight
Available since 8.0
Available since 8.1