IndexOf(Object, Int32,Int32) method in ArrayList

In this article I will discuss the IndexOf(Object, Int32,Int32) method of ArrayList.
  • 1947

Introduction

IndexOf(Object, Int32,Int32) method searches for the specified object and returns the zero-based index of the first occurrence within the range of elements in the ArrayList that starts at the specified index and contains the specified number of elements. That means that this method searches from the index value range that we give and return the object's index value.

Example

namespace ConsoleApplication3

{

    class Program

    {

        static void Main(string[] args)

        {

            ArrayList arr = new ArrayList();

            arr.Add("Red");

            arr.Add("Pink");

            arr.Add("Orange");

            arr.Add("Yellow");

            arr.Add("Blue");

            arr.Add("Gray");

            arr.Add("White");

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

            foreach (object obj in arr)

            {

                Console.WriteLine(obj);

            }

            Console.WriteLine("The index value of Red is:" + arr.IndexOf("Red", 0, 3));

            Console.WriteLine("The index value of Orange is:" + arr.IndexOf("Orange", 1, 4));

            Console.WriteLine("The index value of Blue is:" + arr.IndexOf("Blue", 2,5));

        }

    }

}


Output

indexof1.jpg
 

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

Categories

More Articles

© 2013 dotNetheaven. All rights reserved.