基于c# 接口的實例詳解
更新時間:2013年06月09日 10:23:38 作者:
本篇文章是對c#中的接口進行了詳細的分析介紹,需要的朋友參考下
復制代碼 代碼如下:
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)取走了{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);
}
}
}
復制代碼 代碼如下:
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#實現(xiàn)自定義windows系統(tǒng)日志的方法
這篇文章主要介紹了C#實現(xiàn)自定義windows系統(tǒng)日志的方法,涉及C#針對windows系統(tǒng)日志的創(chuàng)建、讀寫及刪除技巧,非常具有實用價值,需要的朋友可以參考下2015-08-08
C# 中 System.Index 結構體和 Hat 運算符(^)的使用示例
這篇文章主要介紹了C# 中 System.Index 結構體和 Hat 運算符(^)的使用示例,幫助大家更好的理解和使用C#,感興趣的朋友可以了解下2020-09-09
C#中GraphicsPath的AddString方法用法實例
這篇文章主要介紹了C#中GraphicsPath的AddString方法用法,實例分析了AddString方法添加字符串的相關使用技巧,需要的朋友可以參考下2015-06-06
C#使用foreach循環(huán)遍歷數(shù)組完整實例
這篇文章主要介紹了C#使用foreach循環(huán)遍歷數(shù)組,結合完整實例形式較為詳細的分析了C#遍歷數(shù)組的相關技巧,需要的朋友可以參考下2016-06-06
C#數(shù)據(jù)結構之單鏈表(LinkList)實例詳解
這篇文章主要介紹了C#數(shù)據(jù)結構之單鏈表(LinkList)實現(xiàn)方法,結合實例形式較為詳細的分析了單鏈表的原理、定義與C#具體實現(xiàn)技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-11-11

