基于c# 接口的實(shí)例詳解
更新時(shí)間:2013年06月09日 10:23:38 作者:
本篇文章是對c#中的接口進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
復(fù)制代碼 代碼如下:
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("您現(xiàn)在的存款是:{0}",balance);
}
public bool PayOut(decimal Account)
{
if (Balance > Account)
{
balance -= Account;
Console.WriteLine("您已經(jīng)取走了{(lán)0},還剩下余額是:{1}", Account, balance);
return true;
}
Console.WriteLine("提款失??!");
return false;
}
public decimal Balance
{
get { return balance; }
}
public override string ToString()
{
return string.Format("您現(xiàn)在的存款是:{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);
}
}
}
復(fù)制代碼 代碼如下:
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);
}
}
相關(guān)文章
C#實(shí)現(xiàn)自定義windows系統(tǒng)日志的方法
這篇文章主要介紹了C#實(shí)現(xiàn)自定義windows系統(tǒng)日志的方法,涉及C#針對windows系統(tǒng)日志的創(chuàng)建、讀寫及刪除技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-08-08
C# 中 System.Index 結(jié)構(gòu)體和 Hat 運(yùn)算符(^)的使用示例
這篇文章主要介紹了C# 中 System.Index 結(jié)構(gòu)體和 Hat 運(yùn)算符(^)的使用示例,幫助大家更好的理解和使用C#,感興趣的朋友可以了解下2020-09-09
C#中GraphicsPath的AddString方法用法實(shí)例
這篇文章主要介紹了C#中GraphicsPath的AddString方法用法,實(shí)例分析了AddString方法添加字符串的相關(guān)使用技巧,需要的朋友可以參考下2015-06-06
C#使用foreach循環(huán)遍歷數(shù)組完整實(shí)例
這篇文章主要介紹了C#使用foreach循環(huán)遍歷數(shù)組,結(jié)合完整實(shí)例形式較為詳細(xì)的分析了C#遍歷數(shù)組的相關(guān)技巧,需要的朋友可以參考下2016-06-06
C#自定義實(shí)現(xiàn)多程序共享內(nèi)存空間
這篇文章主要為大家詳細(xì)介紹了C#如何自定義實(shí)現(xiàn)多程序共享內(nèi)存空間,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-10-10
C#數(shù)據(jù)結(jié)構(gòu)之單鏈表(LinkList)實(shí)例詳解
這篇文章主要介紹了C#數(shù)據(jù)結(jié)構(gòu)之單鏈表(LinkList)實(shí)現(xiàn)方法,結(jié)合實(shí)例形式較為詳細(xì)的分析了單鏈表的原理、定義與C#具體實(shí)現(xiàn)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-11-11
基于C#實(shí)現(xiàn)手機(jī)號碼歸屬地接口調(diào)用
這篇文章主要介紹了基于C#實(shí)現(xiàn)手機(jī)號碼歸屬地接口調(diào)用的相關(guān)資料,需要的朋友可以參考下2016-02-02

