这是《C#高级编程》里的一个例子,官方网站太慢上不去,只能在这里提问了Bank.cs: public interface IBankAccount
{
void PayIn(decimal amount);
} public class GoldAccount : IBankAccount
{
private decimal balance;
public void PayIn(decimal amount)
{
//........
}
} public class SaverAccount : IBankAccount
{
private decimal balance;
public void PayIn(decimal amount)
{
//......
}
} //派生的接口 public interface ITransferBankAccount : IBankAccount
{
bool TransferTo(IBankAccount destination, decimal amount);
}
public class CurrentAccount:ITransferBankAccount
{
private decimal balance;
public void PayIn(decimal amount)
{
//.....
}
public bool TranferTo(IBankAccount destination, decimal amount)
{
//代码略~
}//问题就在这里了。。
}Program.cs:
static void Main(string[] args)
{
IBankAccount venusAccount = new SaverAccount();
CurrentAccount jupiterAccount = new CurrentAccount();
venusAccount.PayIn(200);
jupiterAccount.PayIn(500);
jupiterAccount.TransferTo(venusAccount, 100);//这里...
Console.WriteLine(venusAccount.ToString());
Console.WriteLine(jupiterAccount.ToString());
Console.ReadLine();
}代码简略了一些,问题不太,主要问题是编译时出现以下问题:
“BankAccount.CurrentAccount”不会实现接口成员“BankAccount.ITransferBankAccount.TransferTo(BankAccount.IBankAccount, decimal)”
问题出在哪呢?谢大侠帮忙解决一下
{
void PayIn(decimal amount);
} public class GoldAccount : IBankAccount
{
private decimal balance;
public void PayIn(decimal amount)
{
//........
}
} public class SaverAccount : IBankAccount
{
private decimal balance;
public void PayIn(decimal amount)
{
//......
}
} //派生的接口 public interface ITransferBankAccount : IBankAccount
{
bool TransferTo(IBankAccount destination, decimal amount);
}
public class CurrentAccount:ITransferBankAccount
{
private decimal balance;
public void PayIn(decimal amount)
{
//.....
}
public bool TranferTo(IBankAccount destination, decimal amount)
{
//代码略~
}//问题就在这里了。。
}Program.cs:
static void Main(string[] args)
{
IBankAccount venusAccount = new SaverAccount();
CurrentAccount jupiterAccount = new CurrentAccount();
venusAccount.PayIn(200);
jupiterAccount.PayIn(500);
jupiterAccount.TransferTo(venusAccount, 100);//这里...
Console.WriteLine(venusAccount.ToString());
Console.WriteLine(jupiterAccount.ToString());
Console.ReadLine();
}代码简略了一些,问题不太,主要问题是编译时出现以下问题:
“BankAccount.CurrentAccount”不会实现接口成员“BankAccount.ITransferBankAccount.TransferTo(BankAccount.IBankAccount, decimal)”
问题出在哪呢?谢大侠帮忙解决一下
少个s