Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

1 Answer
Samual Sam

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

Live Demo

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

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.