SortedList<TKey,TValue>.IndexOfValue(TValue) SortedList<TKey,TValue>.IndexOfValue(TValue) SortedList<TKey,TValue>.IndexOfValue(TValue) SortedList<TKey,TValue>.IndexOfValue(TValue) Method


搜尋指定的值,並傳回整個 SortedList<TKey,TValue> 內第一次出現之以零起始的索引。Searches for the specified value and returns the zero-based index of the first occurrence within the entire SortedList<TKey,TValue>.

 int IndexOfValue(TValue value);
public int IndexOfValue (TValue value);
member this.IndexOfValue : 'Value -> int
Public Function IndexOfValue (value As TValue) As Integer


TValue TValue TValue TValue

要在 SortedList<TKey,TValue> 中尋找的值。The value to locate in the SortedList<TKey,TValue>. 參考類型的值可以是 nullThe 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 , 則會檢查實TValueSystem.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.

這個方法會執行線性搜尋;因此, 平均執行時間與成正比CountThis method performs a linear search; therefore, the average execution time is proportional to Count. 也就是說, 這個方法是 O (n) 運算, 其中nCountThat is, this method is an O(n) operation, where n is Count.