
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Conversion of ArrayList to Array in C#
To convert an ArrayList to Array, use the ToArray() method in C#.
Firstly, set an ArrayList −
ArrayList arrList = new ArrayList(); arrList.Add("one"); arrList.Add("two"); arrList.Add("three");
Now, to convert, use the ToArray() method −
arrList.ToArray(typeof(string)) as string[];
Let us see the complete code −
Example
using System; using System.Collections; public class Program { public static void Main() { ArrayList arrList = new ArrayList(); arrList.Add("one"); arrList.Add("two"); arrList.Add("three"); string[] arr = arrList.ToArray(typeof(string)) as string[]; foreach (string res in arr) { Console.WriteLine(res); } } }
Output
one two three
Advertisements