The System.Collections ArrayList ToArray method is a useful feature in C# that converts an ArrayList collection into an array. This function takes the elements of the ArrayList collection and places them into a new array of the same type.
Code Example:
ArrayList myArrayList = new ArrayList(); myArrayList.Add("Apple"); myArrayList.Add("Banana"); myArrayList.Add("Grapes");
string[] myArray = (string[])myArrayList.ToArray(typeof(string)); foreach (string s in myArray) { Console.WriteLine(s); }
This code creates an ArrayList collection and populates it with three string values. The ToArray method is then used to create a new string array from the collection, which is then output to the console using a foreach loop.
Package Library: System.Collections
C# (CSharp) System.Collections ArrayList.ToArray - 60 examples found. These are the top rated real world C# (CSharp) examples of System.Collections.ArrayList.ToArray extracted from open source projects. You can rate examples to help us improve the quality of examples.