/*
C#: The Complete Reference
by Herbert Schildt
Publisher: Osborne/McGraw-Hill (March 8, 2002)
ISBN: 0072134852
*/
// Use object to create a generic array.
using System;
public class GenericDemo {
public static void Main() {
object[] ga = new object[10];
// store ints
for(int i=0; i < 3; i++)
ga[i] = i;
// store doubles
for(int i=3; i < 6; i++)
ga[i] = (double) i / 2;
// store two strings, a bool, and a char
ga[6] = "Generic Array";
ga[7] = true;
ga[8] = 'X';
ga[9] = "end";
for(int i = 0; i < ga.Length; i++)
Console.WriteLine("ga[" + i + "]: " + ga[i] + " ");
}
}
|