SortedList<TKey,TValue>.IndexOfKey(TKey) 方法

定义

在整个 SortedList<TKey,TValue> 中搜索指定键并返回从零开始的索引。Searches for the specified key and returns the zero-based index within the entire SortedList<TKey,TValue>.

public:
 int IndexOfKey(TKey key);
public int IndexOfKey (TKey key);
member this.IndexOfKey : 'Key -> int
Public Function IndexOfKey (key As TKey) As Integer

参数

key
TKey

要在 SortedList<TKey,TValue> 中定位的键。The key to locate in the SortedList<TKey,TValue>.

返回

如果找到,则为整个 SortedList<TKey,TValue>key 的从零开始的索引;否则为 -1。The zero-based index of key within the entire SortedList<TKey,TValue>, if found; otherwise, -1.

异常

keynullkey is null.

注解

此方法执行二进制搜索;因此,此方法是 O (log n)操作,其中nCountThis method performs a binary search; therefore, this method is an O(log n) operation, where n is Count.

适用于

另请参阅