Convert list to array with ToArray in CSharp
Description
The following code shows how to convert list to array with ToArray.
Example
using System;/* ww w.j a v a 2 s. c o m*/
using System.Linq;
using System.Collections;
using System.Collections.Generic;
public class MainClass {
public static void Main() {
string[] presidents = {"G", "H", "a", "H", "over", "Jack"};
string[] names = presidents.OfType<string>().ToArray();
foreach (string name in names)
Console.WriteLine(name);
}
}
The code above generates the following result.