Contain method in ArrayList

In this article I will explain the contain method of arraylist.
  • 2269

Contain method find that whether the particular element is exists in the arraylist or not,if the element is exists then it return true otherwise return false.

Example

namespace ConsoleApplication1

{

    class Program

    {

        static void Main(string[] args)

        {

            ArrayList numbers = new ArrayList();

            numbers.Add(10);

            numbers.Add(22);

            numbers.Add(3);

            numbers.Add(5);

            numbers.Add(9);

            Console.WriteLine("The elements of the arraylist are:");

            foreach (int i in numbers)

            {

                Console.WriteLine(i);

            }

            Console.WriteLine("The element 22 contain in the ararylist is:" + numbers.Contains(22));

            Console.WriteLine("The element 12 contain in the ararylist is:" + numbers.Contains(12));

            Console.WriteLine("The element 10 contain in the ararylist is:" + numbers.Contains(10));

            Console.WriteLine("The element 9 contain in the ararylist is:" + numbers.Contains(9));

            Console.WriteLine("The element 40 contain in the ararylist is:" + numbers.Contains(40));

            Console.WriteLine("The element 5 contain in the ararylist is:" + numbers.Contains(5));

        }

    }

}


Output

 

contain.jpg 

 

Further Readings
 
You may also want to read these related articles.

Ask Your Question 

Got a programming related question? You may want to post your question here

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.