How to Insert element at the beginning of ArrayList in C#

1 Answer

0 votes
using System;
using System.Collections;
      
class Program
{
    public static void PrintArrayList(ArrayList list) { 
         foreach (var e in list) {
            Console.WriteLine(e);
        }
    } 
    static void Main() {
        ArrayList al = new ArrayList();
             
        al.Add("java");
        al.Add("c#");
        al.Add("python");
        al.Add("c");
        al.Add("php");
         
        PrintArrayList(al);
                 
        al.Insert(0, "c++"); 
 
        Console.WriteLine("\n\n");
         
        PrintArrayList(al);
    }
}
     
      
      
/*
run:
      
java
c#
python
c
php



c++
java
c#
python
c
php
      
*/

 



answered Apr 22, 2020 by avibootz

Related questions

1 answer 172 views
1 answer 200 views
2 answers 187 views
1 answer 270 views
1 answer 198 views
2 answers 234 views
1 answer 152 views
...