Maha

Maha

  • NA
  • 0
  • 308.7k

NP98 Remove(x) & RemoveAt(0)

Apr 23 2008 6:35 PM

Hi Guys

 

NP98 Remove(x) & RemoveAt(0)

 

In the following program activation of Remove(x) is producing //1 2 output. Activation of RemoveAt(0) is producing //2 3 output.

 

Please explain the reason.

 

Thank you

 

using System;

using System.Collections;

 

class MainClass

{

   static void Main(string[] args)

   {

      ArrayList a = new ArrayList(10);

      int x = 0;

 

      a.Add(++x);

      a.Add(++x);

      a.Add(++x);

 

      a.Remove(x);

      //a.RemoveAt(0);

 

      foreach (int i in a)

         Console.Write(i + " ");

   }

}

//1 2

 

using System;

using System.Collections;

 

class MainClass

{

   static void Main(string[] args)

   {

      ArrayList a = new ArrayList(10);

      int x = 0;

 

      a.Add(++x);

      a.Add(++x);

      a.Add(++x);

 

      //a.Remove(x);

      a.RemoveAt(0);

 

      foreach (int i in a)

         Console.Write(i + " ");

   }

}

//2 3


Answers (2)