static void Main(string[] args) { SampleClass foo1 = new SampleClass(); IControl foo2 = (IControl)foo1; ISurface foo3 = (ISurface)foo1; //foo1.Paint(); foo2.Paint(); foo3.Paint(); Console.WriteLine("Press any key for continuing..."); Console.ReadKey(); }
static void Main(string[] args) { SampleClass fooSampleClass = new SampleClass(); IControl fooIControl = (IControl)fooSampleClass; ISurface fooISurface = (ISurface)fooSampleClass; Console.WriteLine($"fooSampleClass.Paint() 的執行結果"); fooSampleClass.Paint(); Console.WriteLine($"fooIControl.Paint() 的執行結果"); fooIControl.Paint(); Console.WriteLine($"fooISurface.Paint() 的執行結果"); fooISurface.Paint(); Console.WriteLine("Press any key for continuing..."); Console.ReadKey(); }