基于c# 接口的实例详解
时间:2023-10-22 22:22:11
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);
}
}
标签:c#,接口
0
投稿
猜你喜欢
Android自定义view之围棋动画效果的实现
2022-05-07 17:36:38
Android中SurfaceView用法简单实例
2022-01-05 20:10:11
Android使用第三方服务器Bmob实现发送短信验证码
2022-06-25 02:59:37
Java 获取网络302重定向URL的方法
2022-03-25 15:19:46
C#绘制飞行棋地图小程序
2021-11-20 23:19:10
C# Ini文件操作实例
2022-12-31 00:37:45
Java Map简介_动力节点Java学院整理
2023-06-03 20:27:03
C#实现Dictionary字典赋值的方法
2021-12-09 17:55:40
Java 1.8使用数组实现循环队列
2022-02-11 04:00:10
Java Unsafe类实现原理及测试代码
2023-03-10 21:18:13
springboot中项目启动时实现初始化方法加载参数
2023-08-31 06:00:40
教你怎么用Java操作Redis
2023-07-07 22:17:53
有关微博content的封装实现详解
2022-12-02 17:37:53
C# 时间与时间戳互转的方法(13位)
2023-12-04 10:26:39
Android 3D旋转动画效果实现分解
2022-11-14 17:53:00
Java SWT中常见弹出框实例总结
2023-08-22 00:42:22
Mybatis接口式编程的原理
2023-11-27 22:16:05
Android Studio实现简易计算器设计
2022-08-22 18:41:55
Android中处理apple-touch-icon详解
2023-05-09 13:21:31
Java正则验证电话,手机,邮箱,日期,金额的方法示例
2021-06-25 22:37:46