Stack.Contains(Object) 方法

定义

确定某元素是否在 Stack 中。Determines whether an element is in the Stack.

public:
 virtual bool Contains(System::Object ^ obj);
public virtual bool Contains (object obj);
public virtual bool Contains (object? obj);
abstract member Contains : obj -> bool
override this.Contains : obj -> bool
Public Overridable Function Contains (obj As Object) As Boolean

参数

obj
Object

要在 Stack 中定位的对象。The object to locate in the Stack. 该值可以为 nullThe value can be null.

返回

Boolean

如果在 Stack 中找到 obj,则为 true;否则为 falsetrue, if obj is found in the Stack; otherwise, false.

注解

此方法通过调用方法来确定相等性 Object.EqualsThis method determines equality by calling the Object.Equals method.

此方法执行线性搜索;因此,此方法是一个 O(n) 操作,其中 nCountThis method performs a linear search; therefore, this method is an O(n) operation, where n is Count.

从 .NET Framework 2.0 开始,此方法通过将 obj 参数传递到 Equals 集合中的各个对象的方法来测试是否相等。Starting with the .NET Framework 2.0, this method tests for equality by passing the obj argument to the Equals method of individual objects in the collection. 在 .NET Framework 的早期版本中,通过将集合中的各个项传递到参数的方法来进行确定 Equals objIn the earlier versions of the .NET Framework, this determination was made by using passing the individual items in the collection to the Equals method of the obj argument.

适用于