Dictionary<TKey,TValue>.ContainsValue(TValue) Dictionary<TKey,TValue>.ContainsValue(TValue) Dictionary<TKey,TValue>.ContainsValue(TValue) Dictionary<TKey,TValue>.ContainsValue(TValue) Method

定义

确定 Dictionary<TKey,TValue> 是否包含特定值。Determines whether the Dictionary<TKey,TValue> contains a specific value.

public:
 bool ContainsValue(TValue value);
public bool ContainsValue (TValue value);
member this.ContainsValue : 'Value -> bool
Public Function ContainsValue (value As TValue) As Boolean

参数

value
TValue TValue TValue TValue

要在 Dictionary<TKey,TValue> 中定位的值。The value to locate in the Dictionary<TKey,TValue>. 对于引用类型,该值可以为 nullThe value can be null for reference types.

返回

如果 true 包含具有指定值的元素,则为 Dictionary<TKey,TValue>;否则为 falsetrue if the Dictionary<TKey,TValue> contains an element with the specified value; otherwise, false.

注解

此方法使用的默认相等比较器EqualityComparer<T>.Default TValue确定是否相等,字典中的值的类型为。This method determines equality using the default equality comparer EqualityComparer<T>.Default for TValue, the type of values in the dictionary.

此方法执行线性搜索;因此,平均执行时间与成正比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.

适用于

另请参阅