Lookup<TKey,TElement>.Contains(TKey) 方法

定义

确定指定的键是否位于 Lookup<TKey,TElement> 中。Determines whether a specified key is in the Lookup<TKey,TElement>.

public:
 virtual bool Contains(TKey key);
public bool Contains (TKey key);
abstract member Contains : 'Key -> bool
override this.Contains : 'Key -> bool
Public Function Contains (key As TKey) As Boolean

参数

key
TKey

要在 Lookup<TKey,TElement> 中查找的键。The key to find in the Lookup<TKey,TElement>.

返回

Boolean

如果 keyLookup<TKey,TElement> 中,则为 true;否则为 falsetrue if key is in the Lookup<TKey,TElement>; otherwise, false.

实现

示例

下面的示例演示如何使用 Contains 来确定是否 Lookup<TKey,TElement> 包含指定的键。The following example demonstrates how to use Contains to determine whether a Lookup<TKey,TElement> contains a specified key. 此代码示例是为类提供的更大示例的一部分 Lookup<TKey,TElement>This code example is part of a larger example provided for the Lookup<TKey,TElement> class.

// Determine if there is a key with the value 'G' in the Lookup.
bool hasG = lookup.Contains('G');
' Determine if there is a key with the value 'G' in the Lookup.
Dim hasG As Boolean = lookup.Contains("G"c)

适用于