
- 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
Copy the elements of collection over a range of elements in ArrayList in C#
To copy the elements of the collection over a range of elements in ArrayList, the code is as follows −
Example
using System; using System.Collections; public class Demo { public static void Main(){ ArrayList arrList = new ArrayList(); arrList.Add("A"); arrList.Add("B"); arrList.Add("C"); arrList.Add("D"); Console.WriteLine("ArrayList elements..."); for (int i = 0; i < arrList.Count; i++) { Console.WriteLine("" + arrList[i]); } string[] str = { "Demo", "Text" }; arrList.SetRange(0, str); Console.WriteLine("After copying..."); for (int i = 0; i < arrList.Count; i++) { Console.WriteLine("" + arrList[i]); } } }
Output
This will produce the following output −
ArrayList elements... A B C D After copying... Demo Text C D
Example
Let us now see another example −
using System; using System.Collections; public class Demo { public static void Main(){ ArrayList arrList = new ArrayList(); arrList.Add("One"); arrList.Add("Two"); arrList.Add("Three"); arrList.Add("Four"); arrList.Add("Five"); arrList.Add("Six"); arrList.Add("Seven"); arrList.Add("Eight"); Console.WriteLine("ArrayList elements..."); for (int i = 0; i < arrList.Count; i++) { Console.WriteLine("" + arrList[i]); } string[] str = { "Demo", "Text" }; arrList.SetRange(2, str); Console.WriteLine("After copying..."); for (int i = 0; i < arrList.Count; i++) { Console.WriteLine("" + arrList[i]); } } }
Output
This will produce the following output −
ArrayList elements... One Two Three Four Five Six Seven Eight After copying... One Two Demo Text Five Six Seven Eight
- Related Articles
- Remove a range of elements from the ArrayList in C#
- Getting an enumerator for a range of elements in the ArrayList in C#
- Append all elements of other Collection to ArrayList in Java
- Copy all elements of ArrayList to an Object Array in Java
- How to copy elements of ArrayList to Java Vector
- Copy Elements of One ArrayList to Another ArrayList with Java Collections Class
- Reverse the order of the elements in the entire ArrayList or in the specified range in C#
- Get the range of elements in a C# list
- Find missing elements of a range in C++
- Copying the elements of ArrayList to a new array in C#
- Adding elements to the end of the ArrayList in C#
- Insert all elements of other Collection to Specified Index of Java ArrayList
- Java Program to append all elements of other Collection to ArrayList
- Remove a range of elements from the List in C#
- Get the number of elements contained in Collection in C#

Advertisements