c#接口应用

 

  1 using  System;
  2 using  study.a;
  3 using  study.b;
  4 using  study;
  5   
  6 namespace  study {
  7
  8public interface IBlankAccount
  9
 10 void PlayIn(decimal amount);
 11 bool Withdraw(decimal amount);
 12 
 13 decimal Balance{
 14 
 15 get;
 16 
 17 }

 18}

 19
 20
 21public interface ITransferBankAccount:IBlankAccount{
 22
 23
 24 bool TransaferTo(IBlankAccount BankName,decimal amcount);
 25 
 26}

 27
 28 
 29
 30
 31public class MainEntry
 32{
 33 static void Main(){
 34 ITransferBankAccount vensAccount=new saveCount();
 35 IBlankAccount jenAccount=new GoldAccount();
 36 vensAccount.PlayIn(400);
 37 jenAccount.PlayIn(500);
 38// Console.WriteLine(vensAccount.ToString());
 39
 40// vensAccount.Withdraw(100);
 41// vensAccount.PlayIn(800);
 42//  vensAccount.Withdraw(200);
 43  vensAccount.TransaferTo(jenAccount,100);
 44 
 45 Console.WriteLine(vensAccount.ToString());
 46  Console.WriteLine(jenAccount.ToString());
 47 }

 48
 49 
 50
 51}
}

 52
 53  
 54
 55
 56 namespace  study.a
 57 {
 58 public class saveCount:ITransferBankAccount{
 59 
 60 private decimal balance;
 61
 62public void PlayIn(decimal amount)
 63
 64{
 65 balance+=amount;
 66
 67}

 68
 69public bool Withdraw(decimal amount)
 70{
 71
 72 if(balance>=amount)
 73 {
 74 balance-=amount;
 75 
 76 return true;
 77 }

 78 Console.WriteLine("取钱失败");
 79 return false;
 80
 81}

 82
 83public decimal Balance{
 84
 85 get{
 86 
 87 return balance;
 88 }

 89
 90}

 91 
 92 
 93public bool TransaferTo(IBlankAccount BankName,decimal amcount)
 94{
 95 bool result;
 96 if((result= Withdraw(amcount))==true)
 97  BankName.PlayIn(amcount);
 98 return result;
 99}

100
101 
102
103
104public override string ToString(){
105 
106 
107 return String.Format("{0,6:c}",balance);
108}

109
110}
}

111
112 namespace  study.b {
113
114 public class GoldAccount:ITransferBankAccount{
115 
116 
117 private decimal balance;
118
119public void PlayIn(decimal amount)
120
121{
122 balance+=amount;
123
124}

125
126public bool Withdraw(decimal amount)
127{
128
129 if(balance>=amount)
130 {
131 balance-=amount;
132 
133 return true;
134 }

135 Console.WriteLine("取钱失败");
136 return false;
137
138}

139
140public decimal Balance{
141
142 get{
143 
144 return balance;
145 }

146
147}

148 
149 
150public bool TransaferTo(IBlankAccount BankName,decimal amcount)
151{
152 bool result;
153 if((result= Withdraw(amcount))==true)
154  BankName.PlayIn(amcount);
155 return result;
156}

157
158 
159
160
161public override string ToString(){
162 
163 
164 return String.Format("{0,6:c}",balance);
165}

166 
167 
168 }
}

169
170  
171
172  
173  
174
175  
176
177  
178
179  
180

转载于:https://www.cnblogs.com/hansan198703/archive/2008/05/23/1205829.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值