C# | Check whether an element is contained in the ArrayList Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report 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. Syntax: 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: Example 1: CSHARP // C# code to check if an element is // contained in ArrayList or not using System; using System.Collections; using System.Collections.Generic; class GFG { // Driver code public static void Main() { // Creating an ArrayList ArrayList myList = new ArrayList(); // Adding elements to ArrayList myList.Add("A"); myList.Add("B"); myList.Add("C"); myList.Add("D"); myList.Add("E"); myList.Add("F"); myList.Add("G"); myList.Add("H"); // To check if the ArrayList Contains element "E" // If yes, then display it's index, else // display the message if (myList.Contains("E")) Console.WriteLine("Yes, exists at index " + myList.IndexOf("E")); else Console.WriteLine("No, doesn't exists"); } } Output:Yes, exists at index 4 Example 2 : CSHARP // C# code to check if an element is // contained in ArrayList or not using System; using System.Collections; using System.Collections.Generic; class GFG { // Driver code public static void Main() { // Creating an ArrayList ArrayList myList = new ArrayList(); // Adding elements to ArrayList myList.Add("5"); myList.Add("7"); myList.Add("9"); myList.Add("11"); myList.Add("12"); myList.Add("16"); myList.Add("20"); myList.Add("25"); // To check if the ArrayList Contains element "24" // If yes, then display it's index, else // display the message if (myList.Contains("24")) Console.WriteLine("Yes, exists at index " + myList.IndexOf("24")); else Console.WriteLine("No, doesn't exists"); } } Output:No, doesn't exists Time complexity: O(n) since using Contains method Auxiliary Space: O(n) where n is the size of the ArrayList Reference: https://learn.microsoft.com/en-us/dotnet/api/system.collections.arraylist.contains?view=netframework-4.7.2 Comment More infoAdvertise with us Next Article C# | Check if the ArrayList has a fixed size S Sahil_Bansall Follow Improve Article Tags : Misc C# CSharp-method CSharp-Collections-Namespace CSharp-Collections-ArrayList +1 More Practice Tags : Misc Similar Reads C# | How to check whether a List contains a specified element List<T>.Contains(T) Method is used to check whether an element is in the List<T> or not. Properties of List: It is different from the arrays. A list can be resized dynamically but arrays cannot.List class can accept null as a valid value for reference types and it also allows duplicate e 2 min read C# | Get the number of elements actually contained in the ArrayList 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.Count property gets the number of elements actually contained in 3 min read Check whether K times of a element is present in array Given an array arr[] and an integer K, the task is to check whether K times of any element are also present in the array. Examples : Input: arr[] = {10, 14, 8, 13, 5}, K = 2 Output: Yes Explanation: K times of 5 is also present in an array, i.e. 10. Input: arr[] = {7, 8, 5, 9, 11}, K = 3 Output: No 8 min read C# | Check if an array contain the elements that match the specified conditions Array.Exists(T[], Predicate<T>) Method is used to check whether the specified array contains elements that match the conditions defined by the specified predicate. Syntax: public static bool Exists<T> (T[] array, Predicate<T> match); Parameters: array: It is a one-dimensional, zero 3 min read C# | Check if the ArrayList has a fixed size 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.IsFixedSize property is used to check whether the ArrayList has a 2 min read C# | Check if an element is in the Collection<T> Collection<T>.Contains(T) method is used to determine whether an element is in the Collection<T>. Syntax: public bool Contains (T item); Here, item is the object to locate in the Collection<T>. The value can be null for reference types. Return Value: This method return True if item 2 min read Like