C# में CopyTo() Method का उपयोग एक Array के Elements को दूसरे Array में Copy करने के लिए किया जाता है। इस Method में, आप Source Array से Copy करने के लिए Starting Index Set कर सकते हैं।
निम्न Syntax है:
CopyTo(dest, index);
यहां dest = Destination Array
index = Starting Index
निम्न Example, C# में Array Class के CopyTo(,) Method के उपयोग को दर्शाता है।
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