Array.Copy : Array « System « C# / C Sharp by API






Array.Copy

  
/*
C#: The Complete Reference 
by Herbert Schildt 

Publisher: Osborne/McGraw-Hill (March 8, 2002)
ISBN: 0072134852
*/

// Copy an array. 
 
using System;  
  
public class CopyDemo {     
  public static void Main() {     
    int[] source = { 1, 2, 3, 4, 5 }; 
    int[] target = { 11, 12, 13, 14, 15 }; 
    int[] source2 = { -1, -2, -3, -4, -5 }; 
 
    // Display source. 
    Console.Write("source: "); 
    foreach(int i in source)  
      Console.Write(i + " "); 
    Console.WriteLine(); 
 
    // Display original target. 
    Console.Write("Original contents of target: "); 
    foreach(int i in target)  
      Console.Write(i + " "); 
    Console.WriteLine(); 
 
    // Copy the entire array. 
    Array.Copy(source, target, source.Length); 
 
    // Display copy. 
    Console.Write("target after copy:  "); 
    foreach(int i in target)  
      Console.Write(i + " "); 
    Console.WriteLine(); 
 
    // Copy into middle of target. 
    Array.Copy(source2, 2, target, 3, 2); 
 
    // Display copy. 
    Console.Write("target after copy:  "); 
    foreach(int i in target)  
      Console.Write(i + " "); 
    Console.WriteLine(); 
  } 
}

   
    
  








Related examples in the same category

1.Array.AsReadOnly
2.Array.BinarySearch
3.Array.Clone
4.Array.ConvertAll
5.Array.CopyTo
6.Array.Count
7.Array.CreateInstance
8.Array.Exists
9.Array.Find
10.Array.FindAll
11.Array.ForEach
12.Array.GetEnumerator()
13.Array.GetLength()
14.Array.GetLowerbound
15.Array.GetUpperBound
16.Array.IndexOf
17.Array.LastIndexOf
18.Array.Length
19.Array.Rank
20.Array.Resize
21.Array.Reverse
22.Array.Reverse(nums, 1, 3)
23.Array.Sort
24.Array.Sort(names, Comparer.DefaultInvariant)
25.Array.SyncRoot