The source code to remove the first occurrence of a specific object from the ArrayList is given below. The given program is compiled and executed successfully.
using System;
using System.Collections;
namespace mynamespace
{
class Program
{
//Entry point of program
static void Main(string[] args)
{
ArrayList List = new ArrayList();
List.Add("ABC");
List.Add("XYZ");
List.Add("PQR");
List.Add(1.15);
List.Add(2.25);
List.Add(3.35);
List.Add(4.45);
List.Add(5.55);
object[] objArray1 = List.ToArray();
Console.WriteLine("Values in array list before Remove");
foreach (object val in objArray1)
{
Console.WriteLine(val);
}
List.Remove("XYZ");
object[] objArray2 = List.ToArray();
Console.WriteLine("\n\nValues in array list after remove");
foreach (object val in objArray2)
{
Console.WriteLine(val);
}
}
}
}
Output:
Values in array list before Remove
ABC
XYZ
PQR
1.15
2.25
3.35
4.45
5.55
Values in array list after remove
ABC
PQR
1.15
2.25
3.35
4.45
5.55
Press any key to continue . . .
Program:
The source code to remove the first occurrence of a specific object from the ArrayList is given below. The given program is compiled and executed successfully.
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer