moe sat

moe sat

  • NA
  • 21
  • 10.4k

In Looping cann't remove and insert ArrayList?

Nov 18 2013 8:46 PM
I am a C# beginner.I've some problem with this exercise.Can you give me some advise?Because I've no ide what should i do.

ArrayList arrayList = new ArrayList();
  Console.Write("Enter code:");
  arrayList.Add(Console.ReadLine());
  Console.Write("Enter qty:");
  arrayList.Add(Convert.ToInt32(Console.ReadLine()));
  Console.Write("Enter code:");
  arrayList.Add(Console.ReadLine());
  Console.Write("Enter qty:");
  arrayList.Add(Convert.ToInt32(Console.ReadLine())); 
 
  ArrayList looplist = new ArrayList(arrayList);

  foreach (object text in looplist)
  {
  if (Convert.ToString(text) == "p")
  {
  arrayList.RemoveAt(0);
  arrayList.Insert(0, "Programming");
  }
  else
  {
  arrayList.RemoveAt(2);
  arrayList.Insert(2, "Graphic");
  }

  Console.WriteLine("{0}", text);
  }



Answers (3)