How to get a range (subset) of elements from 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");
        al.Add("c++"); 
        al.Add("javascript"); 
        al.Add("nodejs"); 

        ArrayList al_range = al.GetRange(2, 3);

        PrintArrayList(al_range);
    }
}
     
      
      
/*
run:
      
python
c
php
      
*/

 



answered Apr 22, 2020 by avibootz

Related questions

1 answer 159 views
1 answer 176 views
1 answer 99 views
2 answers 107 views
107 views asked Mar 24, 2025 by avibootz
2 answers 225 views
...