How to copy the ArrayList to array in C#

1 Answer

0 votes
using System;
using System.Collections;
  
class Program
{
    public static void PrintArray(object[] arr) { 
        foreach (object element in arr) {
          Console.WriteLine(element);
        }
    } 
    static void Main() {
        ArrayList al = new ArrayList();
         
        al.Add("c#");
        al.Add("c");
        al.Add("java");
        al.Add("php");
        al.Add("python");
        
        object[] arr = al.ToArray(); 
 
        PrintArray(arr);
    }
}
 
  
  
/*
run:
  
c#
c
java
php
python
  
*/

 



answered Apr 20, 2020 by avibootz

Related questions

1 answer 191 views
1 answer 166 views
1 answer 242 views
2 answers 134 views
134 views asked Oct 9, 2023 by avibootz
1 answer 250 views
1 answer 135 views
1 answer 179 views
179 views asked Sep 10, 2020 by avibootz
...