If you import the System.Linq
namespace, you can convert an ArrayList
to a generic List by calling Cast and then ToList:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
class Sample
{
public static void Main()
{
ArrayList al = new ArrayList();
al.AddRange(new[] { 1, 5, 9 });
List<int> list = al.Cast<int>().ToList();
foreach(int i in list){
Console.WriteLine(i);
}
}
}
The output:
1
5
9
java2s.com | Contact Us | Privacy Policy |
Copyright 2009 - 12 Demo Source and Support. All rights reserved. |
All other trademarks are property of their respective owners. |