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 188 views
1 answer 214 views
2 answers 193 views
1 answer 281 views
1 answer 201 views
2 answers 238 views
1 answer 157 views
...