ArrayList.Contains(Object) 方法

定义

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

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

参数

item
Object

要在 Object 中定位的 ArrayListThe Object to locate in the ArrayList. 该值可以为 nullThe value can be null.

返回

Boolean

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

实现

注解

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

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

从 .NET Framework 2.0 开始,此方法使用集合的对象的 EqualsCompareTo 方法 item 来确定项是否存在。Starting with the .NET Framework 2.0, this method uses the collection's objects' Equals and CompareTo methods on item to determine whether item exists. 在 .NET Framework 的早期版本中,此决定是通过对 Equals CompareTo item 集合中的对象使用参数的和方法进行的。In the earlier versions of the .NET Framework, this determination was made by using the Equals and CompareTo methods of the item parameter on the objects in the collection.

适用于

另请参阅