![]() |
VOOZH | about |
List<T>.FindIndex Method is used to search for an element that matches the conditions defined by a specified predicate and returns the index of the first occurrence within the List<T>. If an item that matches the conditions is not found then this method will return -1. There are 3 methods in the overload list of this method as follows:
This method is used to search for an element that matches the conditions defined by the specified predicate and returns the zero-based index of the first occurrence within the entire List<T>.
Syntax: public int FindIndex (Predicate<T> match);
Parameter:
match: It is the Predicate<T> delegate that defines the conditions of the element to search for.
Return Value: It returns the index of the first occurrence of an element that matches the conditions defined by the match, if found. If not found it returns -1. Exception: This method will give ArgumentNullException if the match is null.
Example:
'C' starts at index 0 'P' starts at index 4
This method searches for an element which matches the conditions defined by the specified predicate and returns the index of the first occurrence within the range of elements in the List which extends from the specified index to the last element.
Syntax:
public int FindIndex (int startIndex, Predicate<T> match);
Parameter:
Return Value: This method will return the index of the first occurrence of an element that matches the conditions defined by "match", if found. If not found it returns -1. Exceptions:
Example:
Search for 'C' starts at index 1 Search for 'J' starts at index 2
This method searches for an element which 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 that starts at the specified index and contains the specified number of elements.
Syntax
public int FindIndex (int startIndex, int count, Predicate<T> match);
Parameters:
Return Value: This method will return the index of the first occurrence of an element that matches the conditions defined by "match", if found. If not found it returns -1. Exceptions:
Example:
Search for 'C' starts at index 0 Search for 'J' starts at index 3
Reference: