CollectionView.IndexOf(Object) Method

Definition

Returns the index at which the specified item is located.

C#
public virtual int IndexOf(object item);

Parameters

item
Object

The item to locate.

Returns

The index at which the specified item is located, or -1 if the item is unknown.

Remarks

If this method returns an index other than -1, it must always be true that view[index-1] < item <= view[index], where the comparisons are done using the IComparer.Compare method of the view, if one exists.

This particular behavior of the method is used by some CollectionChanged event handlers to speed up reaction to insertion and deletion. If the derived class does not override this method, a listener does a binary search using the IComparer.Compare method.

Applies to

Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10