Typed ToArray() from ArrayList

To get a typed Array of type int [] from an ArrayList you can do the following:

(int [])TestArray.ToArray(typeof(int));

First the ToArray() function accepts a System.Type argument which is what it uses to convert the Array to type int. However, the return type of ToArray() is still object so we will need to cast that as well which can be done using the (int []).

Comments