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