Interviews - C# Corner

Sandeep Soni
In an ArrayList, if an item is added using Insert method like below- al.Insert(2, "item") What will happen to the existing item at index 2?
By Sandeep Soni in C# onOct 28 2018
  • Sandeep Soni
    Nov, 2018 15

    It slides to the next position at index 3.

    • 3
  • Vikas Agarwal
    Nov, 2018 20

    It shifted records to other index after index 2, That means it shift 2 index record to 3 and 3 to 4 and so on.

    • 1
  • jubula samal
    Nov, 2018 16

    will be at index 3 position

    • 1
  • Rashmiranjan Dalabehera
    Nov, 2018 15

    After you add item to position 2, it will move existing item to position 3.

    • 1
  • Atish Soni
    Oct, 2019 10

    It will shift to the next index of that ArrayList.

    Please follow the given example below

    ArrayList a1 = new ArrayList();
    a1.Add(“abc”);
    a1.Add(“aa”);
    a1.Add(“baba”);

    //before inserting new element
    Console.WriteLine(a1[2]);

    //adding new element at 2nd index
    a1.Insert(2, “item”);

    //after added
    Console.WriteLine(a1[2]);
    Console.WriteLine(a1[3]);
    //“baba” is shifted at index 3 now

    Console.ReadLine();

    • 0
  • Amit Prakash
    Jan, 2019 2

    item at position 2 will shift down

    • 0

Most Popular Companies

Most Popular Job Functions

MOST LIKED QUESTIONS