private void button5_Click(object sender, EventArgs e) { MachineCat mcat = new MachineCat("叮当"); StoneMonkey wukong = new StoneMonkey("孙悟空"); IChange[] array = new IChange[2]; array[0] = mcat; array[1] = wukong; MessageBox.Show(array[0].ChangeThing("各种各样的东西!")); MessageBox.Show(array[1].ChangeThing("各种各样的东西!")); }
static void Main2(string[] args) { MachineCat mCat = new MachineCat("叮当"); HankDog hDog = new HankDog("汉克"); IChange[] arrayChange = new IChange[2]; arrayChange[0] = mCat; arrayChange[1] = hDog; Console.WriteLine(arrayChange[0].ChangeThing("时光门!")); Console.WriteLine(arrayChange[1].ChangeThing("二郎神!")); Console.ReadKey(); }