How to Insert element at a specified index 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++"); 
        al.Insert(2, "javascript"); 
        al.Insert(4, "nodejs"); 
 
        Console.WriteLine("\n\n");
         
        PrintArrayList(al);
    }
}
     
      
      
/*
run:
      
java
c#
python
c
php



c++
java
javascript
c#
nodejs
python
c
php
      
*/

 



answered Apr 22, 2020 by avibootz

Related questions

1 answer 184 views
1 answer 206 views
1 answer 167 views
1 answer 139 views
1 answer 81 views
1 answer 151 views
1 answer 188 views
...