同类接口对象的传递

xiaoxiao2021-02-28  113

using System; namespace Test { class Program { static void Main(string[] args) { A testA = new A(); testA.TestA1(); ITest testB = testA; testB.Test1(); Console.Read(); } // 相同接口的赋值,可见testB 获得了A 类的test1方法的全部过程,虽然不能访问A类的“非接口”属性和方法。输出如下: //Method Test A1 //Method TestA class //Method Test A1 } interface ITest { void Test1(); } class A:ITest { string tag = "A class"; //“非接口”属性或方法。 public void Test1()//“接口”属性或方法。 { Console.WriteLine("Method Test" + tag); this.TestA1(); } public void TestA1()//“非接口”属性或方法。 { Console.WriteLine("Method Test A1"); } } }
转载请注明原文地址: https://www.6miu.com/read-64474.html

最新回复(0)