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
How to copy a section of one Array to another in C#?
The Array.Copy() method in C# is used to copy section of one array to another array.
The following is the syntax −
Array.Copy(src, dest, length);
Here,
src = array to be copied
dest = destination array
length = how many elements to copy
The following is an example showing the usage of Copy(,,) method of array class in C# −
Example
using System;
class Program {
static void Main() {
int[] arrSource = new int[4];
arrSource[0] = 1;
arrSource[1] = 2;
arrSource[2] = 3;
arrSource[3] = 4;
int[] arrTarget = new int[2];
Array.Copy(arrSource, arrTarget, 2);
Console.WriteLine("Destination Array ...");
foreach (int value in arrTarget) {
Console.WriteLine(value);
}
}
}Advertisements