| What’s the difference between the System.Array.CopyTo() and
System.Array.Clone()? The Clone() method returns a new array (a shallow copy) object containing all the elements in the original array. The CopyTo() method copies the elements into another existing array. Both perform a shallow copy. A shallow copy means the contents (each array element) contains references to the same object as the elements in the original array. A deep copy (which neither of these methods performs) would create a new instance of each element's object, resulting in a different, yet identacle object. |
using System;
//csc test_array_6.cs
namespace clonesort
{
class sortarray
{
public static void cloning(string[] word)
{
Console.WriteLine("Sorted Array:");
Array.Sort(word);
foreach (string str in word)
{
Console.WriteLine(str);
}
//return word;
}
}
class test
{
static void Main(string[] str)
{
Console.Write("Now hit enter :");
// to hold the curosr for enter key press
Console.ReadLine();
string[] a_str= (string[]) str.Clone();
sortarray.cloning(a_str);
}
}
//
}
|
![]() |