Insert(), AddRange(), and InsertRange() methods : ArrayList : Data Structure C# Examples


C# Examples » Data Structure » ArrayList »

 

Insert(), AddRange(), and InsertRange() methods









    
using  System;
using  System.Collections;

class  MainClass
{
    public  static  void  Main()
    {
        ArrayList  myArrayList  =  new  ArrayList();
        
        myArrayList.Add("is");
        myArrayList.Insert(1,  "is");
        string[]  myStringArray  =  {"a",  "test"};
        myArrayList.AddRange(myStringArray);
        string[]  anotherStringArray  =  {"Here's",  "some",  "more",  "text"};
        myArrayList.InsertRange(myArrayList.Count,  anotherStringArray);

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



Output

myArrayList[0] = is
myArrayList[1] = is
myArrayList[2] = a
myArrayList[3] = test
myArrayList[4] = Here's
myArrayList[5] = some
myArrayList[6] = more
myArrayList[7] = text


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Data Structure
» ArrayList