Copy Method (Static Method In Array Class)
Syntax for Copy Method is :- Copy(sourcearray,targetarray,length)
Copy array is a static method in Array Class. It copy element value from one array to another till the length specified in the copy method.
--------------------------------------------------------------------------------------------------------
using System;
class CopyMethod
{
static void Main()
{
int[] arr1 = {1,2,3}; //Source Array
int[] arr2 = new int[3]; //Target Array
foreach(int i in arr1) //Foreach loop on arr1.
{
Console.WriteLine("Element in array is " + i);
}
Console.WriteLine("-----------------------------------");
Array.Copy(arr1,arr2,3); //It copy arr1 values to arr2 till the specified length.
foreach(int i in arr2) //Foreach loop on arr2.
{
Console.WriteLine("Element in array is " + i);
}
Console.WriteLine("-----------------------------------");
}
}
---------------------------------------------------------------------------------------------------------
Copy array is a static method in Array Class. It copy element value from one array to another till the length specified in the copy method.
--------------------------------------------------------------------------------------------------------
using System;
class CopyMethod
{
static void Main()
{
int[] arr1 = {1,2,3}; //Source Array
int[] arr2 = new int[3]; //Target Array
foreach(int i in arr1) //Foreach loop on arr1.
{
Console.WriteLine("Element in array is " + i);
}
Console.WriteLine("-----------------------------------");
Array.Copy(arr1,arr2,3); //It copy arr1 values to arr2 till the specified length.
foreach(int i in arr2) //Foreach loop on arr2.
{
Console.WriteLine("Element in array is " + i);
}
Console.WriteLine("-----------------------------------");
}
}
---------------------------------------------------------------------------------------------------------
Copy Method (Static Method In Array Class)
Reviewed by Baljeet Singh
on
07:13
Rating:
No comments: