- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- 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 use the CopyTo(,) method of array class in C#
The CopyTo() method in C# is used to copy elements of one array to another array. In this method, you can set the starting index from where you want to copy from the source array.
The following is the syntax.
CopyTo(dest, index);
Here dest = destination array
index= starting index
The following is an example showing the usage of CopyTo(,) method of array class in C#.
Example
using System; class Program { static void Main() { int[] arrSource = new int[4]; arrSource[0] = 5; arrSource[1] = 9; arrSource[2] = 1; arrSource[3] = 3; int[] arrTarget = new int[4]; // CopyTo() method arrSource.CopyTo(arrTarget,0 ); Console.WriteLine("Destination Array ..."); foreach (int value in arrTarget) { Console.WriteLine(value); } } }
Output
Destination Array ... 5 9 1 3
Advertisements