原原本本从书上搬进去的代码,运行调试却不成功!哪位高手帮看一下?
代码如下:
using System;
using System.Collections.Generic;
using System.Text;
namespace interfaceExample
{
public interface IBank
{
void PayIn(float count);
bool withdraw(float count);
float Transfercount
{
get;
}
}
public interface ITransferBankAccount : IBank
{
bool TransferTo(IBank destination,float amount);
}
public class CurrentAccount : ITransferBankAccount
{
private float balance;
public void PanIn(float amount)
{
balance += amount;
}
public bool withdraw(float count)
{
if (balance >= count)
{
balance -= count;
return true;
}
Console.WriteLine("账面出错了!");
return false;
}
public float Transfercount
{
get
{
return balance;
}
}
public bool TransferTo(IBank destination, float amount)
{
bool result;
if ((result = withdraw(amount)) == true)
destination.PayIn(amount);
return result;
}
public override string ToString()
{
return string.Format("当前账目结余={0,6:c}",balance);
}
}
public class BankA : IBank
{
private float transfercount;
public BankA()
{
Console.WriteLine("继承自IBank的BankA");
}
public void PayIn(float count)
{
transfercount += count;
}
public bool withdraw(float count)
{
if (transfercount >= count)
{
transfercount -= count;
return true;
}
Console.WriteLine("账面出错了!");
return false;
}
public float Transfercount
{
get
{
return transfercount;
}
}
public override string ToString()
{
return string.Format("Bank 结余:Transfercount={0,6:c}", transfercount);
}
}
class Program
{
static void Main(string[] args)
{
IBank Account = new BankA();
ITransferBankAccount AccountB = new CurrentAccount();
Account.PayIn(200);
AccountB.PayIn(500);
AccountB.TransferTo(Account,100);
Console.WriteLine(Account.ToString());
Console.WriteLine(AccountB.ToString());
}
}
}
幕布斯7119047
神不在的星期二