C# Array Copy(Array, Int64, Array, Int64, Int64)

Description

Array Copy(Array, Int64, Array, Int64, Int64) copies a range of elements from an Array starting at the specified source index and pastes them to another Array starting at the specified destination index. The length and the indexes are specified as 64-bit integers.

Syntax

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


public static void Copy(
  Array sourceArray,/*w  ww.  ja  v  a  2 s  .c o  m*/
  long sourceIndex,
  Array destinationArray,
  long destinationIndex,
  long length
)

Parameters

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

  • sourceArray - The Array that contains the data to copy.
  • sourceIndex - A 64-bit integer that represents the index in the sourceArray at which copying begins.
  • destinationArray - The Array that receives the data.
  • destinationIndex - A 64-bit integer that represents the index in the destinationArray at which storing begins.
  • length - A 64-bit integer that represents the number of elements to copy. The integer must be between zero and Int32.MaxValue, inclusive.

Returns

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

Example

The following code example shows how to copy from one Array of type Object to another Array of type integer.


//from   w  w  w  .ja va  2  s  .  c o m
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, myIntArray.GetLowerBound(0), myObjArray, myObjArray.GetLowerBound(0), 1 );

      Array.Copy( myObjArray, myObjArray.GetUpperBound(0) - 1, myIntArray, myIntArray.GetUpperBound(0) - 1, 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