we will see the way to convert list to an array. we use .ToArray() parameter less instance method that converts list to an array. Below example shows how list get converted in to array using .ToArray() method:
Example to convert list to array [C#]
using System;
using System.Collections.Generic;
class Program
{
static void Main()
{
// List to convert into Array.
List<string> lstString = new List<string>();
lstString.Add("Convert");
lstString.Add("List");
lstString.Add("TO");
lstString.Add("Array");
// use .ToArray() Method to convert list to array
string[] strArray = lstString.ToArray();
}
}
0 Comments :
Post a Comment