Collection<T>.IndexOf(T) method is used to search for the specified object and returns the zero-based index of the first occurrence within the entire Collection<
T>.
Syntax:
public int IndexOf (T item);
Here,
item is the object to locate in the List<
T>. The value can be
null for reference types.
Return Value: This method returns the zero-based index of the first occurrence of item within the entire Collection<
T>, if found, otherwise, -1.
Below given are some examples to understand the implementation in a better way:
Example 1:
Output:
A
B
C
D
D
E
Index : 3
Example 2: