初学者急求:不会实现接口成员
代码如下:
using System.Collections.Generic;
using System.Text;
using Wrox.ProCSharp;
using Wrox.ProCSharp.VenusBank;
using Wrox.ProCSharp.JupiterBank;
namespace Wrox.ProCSharp
{
public interface lBankAccount
{
void PayIn(decimal amount);
bool WithDraw(decimal amount);
decimal Balance
{
get;
}
}
}
namespace Wrox.ProCSharp.VenusBank
{
public class SaverAccount : lBankAccount
{
private decimal banlance;
public void PayIn(decimal amount)
{
banlance += amount;
}
public bool Withdraw(decimal amount)
{
if(banlance>=amount)
{
banlance -= amount ;
return true;
}
Console.WriteLine("withDraw attempt failed");
return false;
}
public decimal Banlance
{
get
{
return banlance;
}
}
public override string ToString()
{
return string.Format("Verus Bank Saver:Balance={0,6:C}",banlance);
}
}
}
namespace Wrox.ProCSharp.JupiterBank
{
public class GoldAccount : lBankAccount
{
}
}
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
lBankAccount venusAccount = new SaverAccount();
lBankAccount jupiterAccount = new GoldAccount();
venusAccount.PayIn(200);
venusAccount.WithDraw(100);
Console.WriteLine(venusAccount.ToString());
jupiterAccount.PayIn(500);
jupiterAccount.WithDraw(600);
jupiterAccount.WithDraw(100);
Console.WriteLine(jupiterAccount.ToString());
}
}
}
出错:
错误 1 “Wrox.ProCSharp.VenusBank.SaverAccount”不会实现接口成员“Wrox.ProCSharp.lBankAccount.WithDraw(decimal)” d:\wody\Projects\form\ConsoleApplication1\ConsoleApplication1\Program.cs 24 18 ConsoleApplication1
错误 2 “Wrox.ProCSharp.VenusBank.SaverAccount”不会实现接口成员“Wrox.ProCSharp.lBankAccount.Balance” d:\wody\Projects\form\ConsoleApplication1\ConsoleApplication1\Program.cs 24 18 ConsoleApplication1
错误 3 “Wrox.ProCSharp.JupiterBank.GoldAccount”不会实现接口成员“Wrox.ProCSharp.lBankAccount.PayIn(decimal)” d:\wody\Projects\form\ConsoleApplication1\ConsoleApplication1\Program.cs 63 18 ConsoleApplication1
错误 4 “Wrox.ProCSharp.JupiterBank.GoldAccount”不会实现接口成员“Wrox.ProCSharp.lBankAccount.WithDraw(decimal)” d:\wody\Projects\form\ConsoleApplication1\ConsoleApplication1\Program.cs 63 18 ConsoleApplication1
错误 5 “Wrox.ProCSharp.JupiterBank.GoldAccount”不会实现接口成员“Wrox.ProCSharp.lBankAccount.Balance” d:\wody\Projects\form\ConsoleApplication1\ConsoleApplication1\Program.cs 63 18 ConsoleApplication1
------解决方案--------------------using System.Collections.Generic;
using System.Text;
using Wrox.ProCSharp;
using Wrox.ProCSharp.VenusBank;
using Wrox.ProCSharp.JupiterBank;
namespace Wrox.ProCSharp
{