接口实例

本文介绍了一个简单的银行账户类实现,包括存款、取款和余额查询等功能。通过接口IBankAccount定义了基本操作,并通过BankMethod类实现了这些功能。

namespace ConsoleApplication1 { using System; using System.Collections.Generic; using System.Text; public class BankMethod : IBankAccount { decimal balance; public void PayIn(decimal Account) { balance += Account; //Console.WriteLine("您现在的存款是:{0}",balance); } public bool PayOut(decimal Account) { if (Balance > Account) { balance -= Account; Console.WriteLine("您已经取走了{0},还剩下余额是:{1}", Account, balance); return true; } Console.WriteLine("提款失败!"); return false; } public decimal Balance { get { return balance; } } public override string ToString() { return string.Format("您现在的存款是:{0:C}", balance); } } class Test { static void Main() { IBankAccount Huguo = new BankMethod(); IBankAccount guo = new BankMethod(); Huguo.PayIn(10000); guo.PayIn(200000); Console.WriteLine(Huguo.ToString()); Console.WriteLine(guo.ToString()); //BankMethod Bank = new BankMethod(); //Bank.PayIn(200000); //Bank.PayOut(30000); } } } namespace ConsoleApplication1 { public interface IBankAccount { void PayIn(decimal amount); bool PayOut(decimal amount); decimal Balance { get; } } public interface IBankTransfer:IBankAccount { bool Transfer(IBankAccount Action,decimal amount); } }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值