Using the GetRange() method to get two elements from myArrayList, starting at index 1 : ArrayList : Data Structure C# Examples


C# Examples » Data Structure » ArrayList »

 

Using the GetRange() method to get two elements from myArrayList, starting at index 1









    
using  System;
using  System.Collections;

class  MainClass
{
    public  static  void  Main()
    {
        ArrayList  myArrayList  =  new  ArrayList();
        myArrayList.Add("A");
        myArrayList.Add("A");
        myArrayList.Add("A");
        myArrayList.Add("A");
        myArrayList.Add("A");
        myArrayList.Add("A");
        myArrayList.Add("A");
        myArrayList.Add("A");
        myArrayList.Add("A");
        myArrayList.Add("A");
        

        string[]  anotherStringArray  =  {"Here's",  "some",  "more",  "text"};
        myArrayList.SetRange(0,  anotherStringArray);

        ArrayList  anotherArrayList  =  myArrayList.GetRange(1,  2);
        DisplayArrayList("anotherArrayList",  anotherArrayList);

    }
    public  static  void  DisplayArrayList(string  arrayListName,  ArrayList  myArrayList)
    {
        for  (int  i  =  0;  i  <  myArrayList.Count;  i++){
            Console.WriteLine(arrayListName  +  "["  +  i  +  "]  =  "  +
                myArrayList[i]);
        }
    }
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Data Structure
» ArrayList