Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

40,026 questions

51,981 answers

573 users

How to convert ArrayList to List in C#

2 Answers

0 votes
using System;
using System.Collections;
using System.Collections.Generic;
 
static class LST {
    public static List<T> ToList<T>(this ArrayList al) {
        List<T> list = new List<T>(al.Count);
        
        foreach (T n in al) {
            list.Add(n);
        }
        return list;
    }
}
 
class Program {
    static void Main() {
        ArrayList arrayList = new ArrayList(){"c++", "c#", "c", "java"};
 
        List<string> list = arrayList.ToList<string>();
         
        foreach (string n in list) {
            Console.WriteLine(n);
        }
    }
}
 
 
 
 
/*
run:
 
c++
c#
c
java
 
*/

 



answered Feb 9, 2017 by avibootz
edited May 9, 2024 by avibootz
0 votes
using System;
using System.Collections;
using System.Collections.Generic;
 
static class LST {
    public static List<T> ToList<T>(this ArrayList al) {
        List<T> list = new List<T>(al.Count);
        
        foreach (T n in al) {
            list.Add(n);
        }
        return list;
    }
}
 
class Program {
    static void Main() {
        ArrayList arrayList = new ArrayList(){4, 1, 9, 5};
 
        List<int> list = arrayList.ToList<int>();
         
        foreach (int n in list) {
            Console.WriteLine(n);
        }
    }
}
 
 
 
 
/*
run:
 
4
1
9
5
 
*/

 



answered Feb 9, 2017 by avibootz
edited May 9, 2024 by avibootz

Related questions

7 answers 479 views
479 views asked Sep 11, 2019 by avibootz
1 answer 86 views
1 answer 147 views
147 views asked Sep 10, 2020 by avibootz
1 answer 169 views
169 views asked Jan 28, 2019 by avibootz
1 answer 140 views
1 answer 90 views
1 answer 89 views
...