

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
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
- Related Questions & Answers
- How do you convert list to array in Java?
- How to convert a list into an array in R?
- How do you convert an ArrayList to an array in Java?
- 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 empty an array in C#?
- How do you turn a list into a Set in Java?
- Java Program to Convert Array into Collection
- Java Program to Convert Collection into Array
- 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?
- How do you split a list into evenly sized chunks in Python?
- How do you turn an ArrayList into a Set in Java?
- How to copy a List collection to an array?
- How do you convert a string to a character array in JavaScript?
Advertisements