C# Array Copy(Array, Array, Int32)

Description

Array Copy(Array, Array, Int32) copies a range of elements from an Array starting at the first element and pastes them into another Array starting at the first element. The length is specified as a 32-bit integer.

Syntax

Array.Copy(Array, Array, Int32) has the following syntax.


public static void Copy(
  Array sourceArray,//www .  j  a  v a  2 s .c  o m
  Array destinationArray,
  int length
)

Parameters

Array.Copy(Array, Array, Int32) has the following parameters.

  • sourceArray - The Array that contains the data to copy.
  • destinationArray - The Array that receives the data.
  • length - A 32-bit integer that represents the number of elements to copy.

Returns

Array.Copy(Array, Array, Int32) method returns

Example


//from w w  w . j  a  v a 2s .c om
using System;
public class SamplesArray  {
   public static void Main()  {
      Array myIntArray=Array.CreateInstance( typeof(System.Int32), 5 );
      for ( int i = myIntArray.GetLowerBound(0); i <= myIntArray.GetUpperBound(0); i++ )
         myIntArray.SetValue( i+1, i );

      Array myObjArray = Array.CreateInstance( typeof(System.Object), 5 );
      for ( int i = myObjArray.GetLowerBound(0); i <= myObjArray.GetUpperBound(0); i++ )
         myObjArray.SetValue( i+26, i );

      Array.Copy( myIntArray, myObjArray, 2 );


   }
}

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