 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How do you convert a list collection into an array in C#?
Firstly, set a list collection −
List < string > myList = new List < string > (); myList.Add("RedHat"); myList.Add("Ubuntu"); Now, use ToArray() to convert the list to an array −
string[] str = myList.ToArray();
The following is the complete code −
Example
using System; using System.Collections.Generic; public class Program {    public static void Main() {       List < string > myList = new List < string > ();       myList.Add("RedHat");       myList.Add("Ubuntu");       Console.WriteLine("List...");       foreach(string value in myList) {          Console.WriteLine(value);       }       Console.WriteLine("Converting to Array...");       string[] str = myList.ToArray();       foreach(string s in myList) {          Console.WriteLine(s);       }    } }  Output
List... RedHat Ubuntu Converting to Array... RedHat Ubuntu
Advertisements
 