ReadOnlyCollection<T>.IndexOf(T) 方法
定义
搜索指定的对象,并返回整个 ReadOnlyCollection<T> 中第一个匹配项的从零开始的索引。Searches for the specified object and returns the zero-based index of the first occurrence within the entire ReadOnlyCollection<T>.
public:
virtual int IndexOf(T value);
public int IndexOf (T value);
abstract member IndexOf : 'T -> int
override this.IndexOf : 'T -> int
Public Function IndexOf (value As T) As Integer
参数
- value
- T
要在 List<T> 中定位的对象。The object to locate in the List<T>. 对于引用类型,该值可以为 null。The value can be null for reference types.
返回
如果找到,则为整个 item 中 ReadOnlyCollection<T> 第一个匹配项的从零开始的索引;否则为 -1。The zero-based index of the first occurrence of item within the entire ReadOnlyCollection<T>, if found; otherwise, -1.
实现
注解
ReadOnlyCollection<T>向前搜索从第一个元素开始,到最后一个元素结束。The ReadOnlyCollection<T> is searched forward starting at the first element and ending at the last element.
此方法使用默认比较器确定相等性 EqualityComparer<T>.Default 。This method determines equality using the default comparer EqualityComparer<T>.Default.
此方法执行线性搜索;因此,此方法是 O (n) 操作,其中 n 是 Count 。This method performs a linear search; therefore, this method is an O(n) operation, where n is Count.