How to convert ArrayList to array in C#

1 Answer

0 votes
using System;
using System.Collections;

class Program
{
    static void Main() {
        ArrayList list = new ArrayList(){"c#", "c", "c++",  "php"};

        string[] arr = list.ToArray(typeof(string)) as string[];

        foreach (string s in arr) {
            Console.WriteLine(s);
        }
    }
}




/*
run:

c#
c
c++
php

*/

 



answered Sep 10, 2020 by avibootz

Related questions

1 answer 131 views
1 answer 174 views
1 answer 199 views
199 views asked Jan 28, 2019 by avibootz
2 answers 269 views
269 views asked Feb 9, 2017 by avibootz
1 answer 188 views
1 answer 125 views
125 views asked Apr 20, 2020 by avibootz
7 answers 526 views
526 views asked Sep 11, 2019 by avibootz
...