C# Program to Remove the First Occurrence of a Specific Object From the Arraylist (Arraylist.remove() Method)

You are currently viewing C# Program to Remove the First Occurrence of a Specific Object From the Arraylist (Arraylist.remove() Method)

C# program to remove the first occurrence of a specific object from the ArrayList (ArrayList.Remove() Method)

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);
            }
        }
    }
}
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 . . .

Ranjith Kumar

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply