/*
C# Programming Tips & Techniques
by Charles Wright, Kris Jamsa
Publisher: Osborne/McGraw-Hill (December 28, 2001)
ISBN: 0072193794
*/
//
// CopyPart.cs -- Uses the Array.Copy() method to copy part of an array
// ints into a secton of an array of doubles.
//
// Compile this program with the following command line:
// C:>csc CopyPart.cs
//
namespace nsArray
{
using System;
public class CopyPart
{
static public void Main ()
{
DateTime now = DateTime.Now;
Random rand = new Random ((int) now.Millisecond);
int [] iArr = new int [12]
{
rand.Next() % 101, rand.Next() % 101,
rand.Next() % 101, rand.Next() % 101,
rand.Next() % 101, rand.Next() % 101,
rand.Next() % 101, rand.Next() % 101,
rand.Next() % 101, rand.Next() % 101,
rand.Next() % 101, rand.Next() % 101
};
double [] dArr = new double [14];
Array.Copy (iArr, 2, dArr, 4, 8);
Console.Write ("The dArr contains:\r\n ");
for (int x = 0; x < dArr.Length; ++x)
{
Console.Write ("{0,4:F1} ", dArr[x]);
if (x == 6)
Console.Write("\r\n ");
}
Console.Write ("\r\n\r\nThe iArr contains:\r\n ");
foreach (int x in iArr)
{
Console.Write (x + " ");
}
Console.WriteLine ();
}
}
}
|