代码:

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace 接口
{
/// <summary>
/// 接口:定义一个统一的标准
/// 声明接口,接口中,只包含成员的生命,不包含任何的代码实现。
/// 接口成员总是公有的,不添加也不需要添加public,也不能声明虚方法和虚静态方法
/// </summary>
interface IBankAccount
{
//方法
void PayIn(decimal amount); //方法
bool WithShowMyself(decimal amount); //属性
decimal Balance { get; }
} /// <summary>
/// 继承自IBankAccount的接口
/// </summary>
interface ITransferBankAccount : IBankAccount
{
//转账 :转入的目的地 :转入金额
bool TransferTo(IBankAccount destination, decimal amount);
} class SaveAcount : IBankAccount
{
//私有变量
private decimal banlance; //存款
public void PayIn(decimal amount)
{
banlance += amount;
} //取款
public bool WithShowMyself(decimal amount)
{
if (banlance >= amount)
{
banlance -= amount;
return true;
}
else
{
Console.WriteLine("余额不足!");
return false;
}
} //账户余额
public decimal Balance
{
get
{
return banlance;
}
}
} //实现接口的类的相应成员必须添加public修饰
class ITransferAccount : ITransferBankAccount
{
//私有变量
private decimal banlance; //存款
public void PayIn(decimal amount)
{
banlance += amount;
} //取款
public bool WithShowMyself(decimal amount)
{
if (banlance >= amount)
{
banlance -= amount;
return true;
}
else
{
Console.WriteLine("余额不足!");
return false;
}
} //账户余额
public decimal Balance
{
get
{
return banlance;
}
} //转账
public bool TransferTo(IBankAccount destination, decimal amount)
{
bool result = WithShowMyself(amount); if (result == true)
{
destination.PayIn(amount);
} return result;
}
} class Program
{
static void Main(string[] args)
{
IBankAccount MyAccount = new SaveAcount(); ITransferAccount YourAccount = new ITransferAccount(); MyAccount.PayIn(); YourAccount.PayIn(); YourAccount.TransferTo(MyAccount, ); Console.WriteLine(MyAccount.Balance);//
Console.WriteLine();
Console.WriteLine(YourAccount.Balance);// Console.ReadKey();
}
}
}

最新文章

  1. php : 自定义分页类
  2. (C# &amp; Unity) 脚本语言 ES
  3. jQuery基础之选择器
  4. 跟着鸟哥学Linux系列笔记3-第11章BASH学习
  5. SAP iDoc 概念及管理
  6. LeetCode 笔记系列 19 Scramble String [合理使用递归]
  7. StrutsPrepareAndExecuteFilter的作用
  8. matlab添加M_map工具箱(转 http://blog.sina.com.cn/s/blog_491b86bf0100srt9.html)
  9. 2014辛星完全解读html第五节
  10. C#研究OpenXML之路(1-新建工作簿文件)
  11. Vivo展柜灯怎样设计才吸引大量客户?
  12. Azure 认知服务 (5) 计算机视觉API - 使用C#代码实现读取图片中的文字(OCR)功能
  13. 使用telnet发送HTTP请求
  14. lua continue实现
  15. java testng框架的windows自动化-自动运行testng程序下篇
  16. Vc数据库编程基础1
  17. Oracle12c Data Guard搭建手册
  18. Ogre 监听类与渲染流程
  19. Laravel5.1 填充数据库
  20. vue 局部引入js插件

热门文章

  1. EBS动态创建账户组合实现
  2. asp.net从客户端检测到有潜在危险的Request.Form 值
  3. 绫致时装讲述O2O细节:野心在“私人定制” - 移动购物 - 亿邦动力网
  4. poj 3691
  5. c++,static 静态成员变量 / 静态成员函数
  6. 机器学习笔记(一)- from Andrew Ng的教学视频
  7. java.lang.NoClassDefFoundError: org.ksoap2.transport.HttpTransportSE异常处理
  8. PHP学习笔记2-流程控制
  9. Vue.js介绍
  10. 一致性算法--Paxos