public static bool TestAs03() { BB aa = new BB(); Dictionary <int, BB> dic = new Dictionary <int, BB>(); dic[0] = aa; IAs1 ias = dic[0] as IAs1; if (ias == null) { throw new Exception("error"); } else { ias.AA1(); } ClassInheritanceTest id = dic[0] as ClassInheritanceTest; if (id == null) { throw new Exception("error2"); } else { id.TestAbstract(); } return(true); }
static void Test01Sub(ClassInheritanceTest cls) { Console.WriteLine("Test invoking from base type..."); cls.TestAbstract(); cls.TestVirtual(); cls.TestField(); }
public static void InheritanceTest01() { TestCls cls = new TestCls(); TestCls2 cls2 = new TestCls2(); Console.WriteLine("Test invoking from sub type..."); Console.WriteLine(cls.ToString()); cls.TestAbstract(); cls.TestVirtual(); cls.TestField(); Console.WriteLine(cls2.ToString()); cls2.TestAbstract(); cls2.TestVirtual(); cls2.TestField(); Console.WriteLine("----------------------------------"); Console.WriteLine("----------------------------------"); Test01Sub(cls); Test01Sub(cls2); Console.WriteLine("TestCls.TestVal2 = " + cls.TestVal2); ClassInheritanceTest.Test3(cls); ClassInheritanceTest.Test3(cls2); }