
- 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 to copy the entire ArrayList to a one-dimensional Array in C# ?
To copy the entire ArrayList to a one-dimensional array, the code is as follows −
Example
using System; using System.Collections; public class Demo { public static void Main(){ ArrayList list = new ArrayList(); list.Add("AB"); list.Add("BC"); list.Add("CD"); list.Add("EF"); list.Add("GH"); list.Add("IJ"); list.Add("KL"); list.Add("MN"); String[] strArr = new String[10]; Console.WriteLine("ArrayList..."); foreach(Object obj in list) Console.WriteLine("{0}", obj); list.CopyTo(strArr); Console.WriteLine("
String Array after copying elements from ArrayList..."); foreach(Object ob in strArr) Console.WriteLine("{0}", ob); } }
Output
This will produce the following output −
ArrayList... AB BC CD EF GH IJ KL MN String Array after copying elements from ArrayList... AB BC CD EF GH IJ KL MN
Example
Let us now see another example −
using System; using System.Collections; public class Demo { public static void Main(){ ArrayList list = new ArrayList(); list.Add(100); list.Add(200); list.Add(300); list.Add(400); list.Add(500); list.Add(600); list.Add(700); list.Add(800); list.Add(900); list.Add(1000); int[] intArr = new int[10]; Console.WriteLine("ArrayList..."); foreach(Object obj in list) Console.WriteLine("{0}", obj); list.CopyTo(intArr); Console.WriteLine("
Integer Array after copying elements from ArrayList..."); foreach(Object ob in intArr) Console.WriteLine("{0}", ob); } }
Output
This will produce the following output −
ArrayList... 100 200 300 400 500 600 700 800 900 1000 Integer Array after copying elements from ArrayList... 100 200 300 400 500 600 700 800 900 1000
- Related Articles
- Copy the entire LinkedList to Array in C#
- Copy Elements of One ArrayList to Another ArrayList with Java Collections Class
- How to Copy the entire contents of a directory in C#?
- How to print one dimensional array in reverse order?
- How to copy or clone a Java ArrayList?
- How to copy a section of one Array to another in C#?
- How to create a shallow copy of ArrayList in C#?
- Copy all elements of ArrayList to an Object Array in Java
- Copying the entire ArrayList to 1-D Array starting at the specified index in C#
- How to image copy the entire DB2 table TAB1 into a dataset?
- Copying the Queue elements to one-dimensional array in C#
- How to copy elements of ArrayList to Java Vector
- How to sort one dimensional array in descending order using Array Class method?
- Split one-dimensional array into two-dimensional array JavaScript
- How to set a value to the element at the specified position in the one-dimensional array in C#

Advertisements