ArrayList represents an ordered collection of an object that can be indexed individually. It is basically an alternative to an array. It also allows dynamic memory allocation, adding, searching and sorting items in the list. ArrayList.Contains(Object) method determines whether the element exists in ArrayList or not.
Properties of ArrayList Class:
- Elements can be added or removed from the Array List collection at any point in time.
- The ArrayList is not guaranteed to be sorted.
- The capacity of an ArrayList is the number of elements the ArrayList can hold.
- Elements in this collection can be accessed using an integer index. Indexes in this collection are zero-based.
- It also allows duplicate elements.
- Using multidimensional arrays as elements in an ArrayList collection is not supported.
public virtual bool Contains (object item);
Here, item is an Object to locate in the ArrayList. The value can be null.
Return Value: This method will return True if the item found in the ArrayList otherwise it returns False.
Note: This method performs a linear search, therefore, this method is an O(n) operation, where n is Count.
Below are the programs to illustrate the ArrayList.Contains(Object) method:
Yes, exists at index 4
Example 2 :
No, doesn't exists
- C# | Get the number of elements actually contained in the ArrayList
- C# | Get or set the element at the specified index in ArrayList
- C# | Insert an element into the ArrayList at the specified index
- C# | Remove the element at the specified index of the ArrayList
- C# | Check if the ArrayList is read-only
- C# | Check if two ArrayList objects are equal
- C# | Check if the ArrayList has a fixed size
- C# | Check if ArrayList is Synchronized (thread safe)
- C# | Number of elements contained in the BitArray
- C# | Get the number of nodes contained in LinkedList<T>
- C# | Get the number of elements contained in SortedList
- C# | Get the number of elements contained in the Queue
- C# | Get the number of key/value pairs contained in ListDictionary
- C# | Get the number of elements contained in the Stack
- C# | Get the number of elements contained in Collection<T>
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.