static void Main(string[] args) { grandfather[] arr = new grandfather[3]; arr[0] = new grandfather(); arr[1] = new father(); arr[2] = new son(); for (int i = 0; i < 3; i++) { Console.WriteLine(arr[i].hello()); } //------------ ArrayList l = new ArrayList(); l.Add(new grandfather()); l.Add(new father()); l.Add(new son()); //l.Add(5); for (int i = 0; i < 3; i++) { Console.WriteLine((l[i] as grandfather).hello()); } foreach (grandfather item in l) { Console.WriteLine((item as grandfather).hello()); } }
static void Main(string[] args) { grandfather[] arr = new grandfather[3]; arr[0] = new grandfather(); arr[1] = new father(); arr[2] = new son(); for (int i = 0; i < 3; i++) { Console.WriteLine(arr[i].hello()); } }