基于c# 接口的实例详解
程序员文章站
2023-12-19 19:50:52
复制代码 代码如下:namespace consoleapplication1{ using system; &n...
复制代码 代码如下:
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);
}
}