手机
当前位置:查字典教程网 >编程开发 >C#教程 >基于c# 接口的实例详解
基于c# 接口的实例详解
摘要:复制代码代码如下:namespaceConsoleApplication1{usingSystem;usingSystem.Collecti...

复制代码 代码如下:

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# 接口的实例详解】相关文章:

基于c#图像灰度化、灰度反转、二值化的实现方法详解

C#控制台带参数程序源码编写实例讲解

C#连接Oracle数据库的实例方法

基于反射解决类复制的实现方法

c# 自定义泛型链表类的详解

c# n个数排序实现代码

基于动态修改App.Config与web.Config的使用详解

c# 开机启动项的小例子

基于TCP异步Socket模型的介绍

深入c#工厂模式的详解

精品推荐
分类导航