static void Main(String[] args) { // 创建两个接口引用变量,接口引用可以引用任何实现该接口的类 IBankAccount vensusAccount = new SaveAccount(); ITransferAccount jupiterAccount = new GoldAccount(); vensusAccount.PayIn(200); jupiterAccount.PayIn(500); // 实现jupiterAccount向venusAccount账户转账 jupiterAccount.TransferTo(vensusAccount, 100); Console.WriteLine(vensusAccount.ToString()); Console.WriteLine(jupiterAccount.ToString()); Console.Read(); }
static void Main(String[] args) { // 创建两个接口引用变量,接口引用可以引用任何实现该接口的类 IBankAccount vensusAccount = new SaveAccount(); IBankAccount jupiterAccount = new GoldAccount(); vensusAccount.PayIn(200); vensusAccount.WithDraw(100); Console.WriteLine(vensusAccount.ToString()); jupiterAccount.PayIn(500); jupiterAccount.WithDraw(600); jupiterAccount.WithDraw(100); Console.WriteLine(jupiterAccount.ToString()); Console.Read(); // 创建接口数组,其中每个元素都是不同的类 IBankAccount[] accounts = new IBankAccount[2]; accounts[0] = new SaveAccount(); accounts[1] = new GoldAccount(); }