
- 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
Copying the entire ArrayList to 1-D Array starting at the specified index in C#
To copy the entire ArrayList to a 1-D array starting at the specified index, the code is as follows −
Example
using System; using System.Collections; public class Demo { public static void Main(){ ArrayList list = new ArrayList(); list.Add("PQ"); list.Add("RS"); list.Add("TU"); list.Add("UV"); list.Add("WX"); list.Add("YZ"); Console.WriteLine("ArrayList elements..."); for (int i = 0; i < list.Count; i++) { Console.WriteLine(list[i]); } String[] strArr = new String[6] {"One", "Two", "Three", "Four", "Five", "Six"}; Console.WriteLine("
Array elements..."); for (int i = 0; i < strArr.Length; i++) { Console.WriteLine(strArr[i]); } list.CopyTo(strArr, 0); Console.WriteLine("
Array elements (updated)..."); for (int i = 0; i < strArr.Length; i++) { Console.WriteLine(strArr[i]); } } }
Output
This will produce the following output −
ArrayList elements... PQ RS TU UV WX YZ Array elements... One Two Three Four Five Six Array elements (updated)... PQ RS TU UV WX YZ
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); Console.WriteLine("ArrayList elements..."); for (int i = 0; i < list.Count; i++) { Console.WriteLine(list[i]); } int[] intArr = new int[5] {10, 20, 30, 40, 50}; Console.WriteLine("
Array elements..."); for (int i = 0; i < intArr.Length; i++) { Console.WriteLine(intArr[i]); } list.CopyTo(intArr, 0); Console.WriteLine("
Array elements (updated)..."); for (int i = 0; i < intArr.Length; i++) { Console.WriteLine(intArr[i]); } } }
Output
This will produce the following output −
ArrayList elements... 100 200 Array elements... 10 20 30 40 50 Array elements (updated)... 100 200 30 40 50
- Related Articles
- Remove the element at the specified index of the ArrayList in C#
- Insert an element into the ArrayList at the specified index in C#
- Get or set the element at the specified index in ArrayList in C#
- Copy StringDictionary to Array at the specified index in C#
- Copying the elements of ArrayList to a new array in C#
- Copy ListDictionary to Array instance at the specified index in C#
- Copy StringCollection at the specified index of array in C#
- Copy OrderedDictionary elements to Array instance at the specified index in C#
- Golang Program to insert an element into the array at the specified index
- Reverse the order of the elements in the entire ArrayList or in the specified range in C#
- Add an element to specified index of ArrayList in Java
- How to copy the entire ArrayList to a one-dimensional Array in C# ?
- Insert at the specified index in StringCollection in C#
- The listIterator() method of CopyOnWriteArrayList in Java starting at a specified position
- Polymer 1.0 dom-repeat should display index starting at 1 with HTML

Advertisements