SortedList<TKey,TValue>.IndexOfValue(TValue) 方法
定义
在整个 SortedList<TKey,TValue> 中搜索指定的值,并返回第一个匹配项的从零开始的索引。Searches for the specified value and returns the zero-based index of the first occurrence within the entire SortedList<TKey,TValue>.
public:
int IndexOfValue(TValue value);
public int IndexOfValue (TValue value);
member this.IndexOfValue : 'Value -> int
Public Function IndexOfValue (value As TValue) As Integer
参数
- value
- TValue
要在 SortedList<TKey,TValue> 中定位的值。The value to locate in the SortedList<TKey,TValue>. 对于引用类型,该值可以为 null
。The value can be null
for reference types.
返回
如果找到,则为整个 value
中 SortedList<TKey,TValue> 第一个匹配项的从零开始的索引;否则为 -1。The zero-based index of the first occurrence of value
within the entire SortedList<TKey,TValue>, if found; otherwise, -1.
注解
此方法使用值类型的默认比较器确定相等性 Comparer<T>.Default TValue
。This method determines equality using the default comparer Comparer<T>.Default for the value type TValue
. Comparer<T>.Default 检查值类型是否 TValue
实现 System.IComparable<T> 并使用该实现(如果可用)。Comparer<T>.Default checks whether the value type TValue
implements System.IComparable<T> and uses that implementation, if available. 如果不是,则 Comparer<T>.Default 检查值类型是否 TValue
实现 System.IComparable 。If not, Comparer<T>.Default checks whether the value type TValue
implements System.IComparable. 如果值类型 TValue
未实现任何一个接口,则此方法将使用 Object.Equals 。If the value type TValue
does not implement either interface, this method uses Object.Equals.
此方法执行线性搜索;因此,平均执行时间与成正比 Count 。This method performs a linear search; therefore, the average execution time is proportional to Count. 也就是说,此方法是 O (n
) 操作,其中 n
是 Count 。That is, this method is an O(n
) operation, where n
is Count.