Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

Creating Console Application to copy Array in C#

Author: DevASP
Download Source Code : 447_Console_copy_array.zip

In this simple article we will see that how we Copy an array from another array in console application.

Simply create a C# console application and write simple code in its main function.

 

//creat first array

 

Array SimpleArray = Array.CreateInstance( Type.GetType("System.Int32"), 10 );

 

//intializing array

  SimpleArray.SetValue(5, 0);

  SimpleArray.SetValue(10, 1);

  SimpleArray.SetValue(15, 2);

  SimpleArray.SetValue(20, 3);

  SimpleArray.SetValue(25, 4);           

  SimpleArray.SetValue(30, 5);

  SimpleArray.SetValue(35, 6);

  SimpleArray.SetValue(40, 7);

  SimpleArray.SetValue(45, 8);

  SimpleArray.SetValue(50, 9);           

 

//create second array

  Array CopiedArray = Array.CreateInstance( Type.GetType("System.Object"), 10 );

                 

//command to copy array

  Array.Copy(SimpleArray, SimpleArray.GetLowerBound(0), CopiedArray, CopiedArray.GetLowerBound(0), 10 );

  int items1 = CopiedArray.GetUpperBound(0);

  Console.WriteLine("Copied Array items");

 

//to show on the screen

  for ( int i =0; i <= items1; i++ )

    Console.WriteLine(CopiedArray.GetValue(i).ToString());

                

    Console.WriteLine("Press Enter To EXIT");

    Console.ReadLine();

This code show the copied array on the screen.

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Sorting of Array Using Console Application in C#

Disclaimer - Privacy
© 2002-2017 DevASP.net