
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
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
- Related Articles
- How do you convert list to array in Java?
- How to convert a list into an array in R?
- How to convert a list collection into a dictionary in Java?
- How do I turn a list into an array in Java?
- How do you convert an ArrayList to an array in Java?
- How to convert a tuple into an array in C#?
- How do you convert an array of ObjectIds into an array of embedded documents with a field containing the original array element value?
- Java Program to Convert Collection into Array
- Java Program to Convert Array into Collection
- How do you empty an array in C#?
- How to copy a List collection to an array?
- How do you turn a list into a Set in Java?
- How to convert an array of characters into a string in C#?
- How to convert an array into a complex array JavaScript?
- Python Program To Convert An Array List Into A String And Viceversa

Advertisements