Click or drag to resize

CollectionExtensionsIndexOfT Method (IEnumerableT, T, IEqualityComparerT)

Searches for the specified object and returns the zero-based index of the first occurrence within all items.

Namespace:  TomsToolbox.Essentials
Assembly:  TomsToolbox.Essentials (in TomsToolbox.Essentials.dll)
Syntax
public static int IndexOf<T>(
	this IEnumerable<T> collection,
	T item,
	IEqualityComparer<T>? comparer
)

Parameters

collection
Type: System.Collections.GenericIEnumerableT
The collection to search.
item
Type: T
The object to locate. The value can be null for reference types.
comparer
Type: System.Collections.GenericIEqualityComparerT
The comparer.

Type Parameters

T
The type of elements in the list.

Return Value

Type: Int32
The zero-based index of the first occurrence of item, if found; otherwise, –1.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IEnumerableT. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
See Also