C# Array Clone

Description

Array Clone creates a shallow copy of the Array.

Syntax

Array.Clone has the following syntax.


public Object Clone()

Returns

Array.Clone method returns A shallow copy of the Array.

Example

The following code example clones a System.Globalization.CultureInfo array and demonstrates the behavior of a shallow copy.


/*  www .j a va  2  s  .  co m*/

using System;
using System.Globalization;
public class SamplesArray  {

   public static void Main()  {
      CultureInfo[] arrCI = new CultureInfo[] { new CultureInfo( "ar-SA", false ), 
                             new CultureInfo( "en-US", false ) };

      // Create a clone of the CultureInfo array.
      CultureInfo[] arrCIClone = (CultureInfo[]) arrCI.Clone();

   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version