代码如下:
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
{
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
解决方案 »
- C#基础问题
- 等了好久都没等到结果,二进制输出,把剩余的分都给你【急】
- 我想了解下怎样通过自己开发的系统发送短信到别人的手机上
- 坐等,急!!!!
- 程序使用SQL数据库,是直接用代码操作好,还是使用向导添加数据源好呢?
- 如何取得指定目录下面的指定的后缀名的所有文件名的数据啊!
- 再问一个问题:VS2005中Addin的问题(在线等).急!!!!!!!!!!!
- 求解一道简单的C#编程题,急!!哪位好心人救救命吧!!
- WEBSERVICE现在用的多不多?有什么好的教程吗?
- datagridview如何绑定数据?
- c# socket.send 如何发送零字节的byte[]
- sqlDataReader关闭
using System.Text;
using Wrox.ProCSharp;
using Wrox.ProCSharp.VenusBank;
using Wrox.ProCSharp.JupiterBank; 这里不是全部引用了吗?我是初学者,可以说详细一点吗?
最好分开。
interface是一个文件,
实现类是一个文件。
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;
}
}
} using System.Collections.Generic;
using System.Text;
using Wrox.ProCSharp;
using Wrox.ProCSharp.VenusBank;
using Wrox.ProCSharp.JupiterBank; 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());
}
}
}
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());
}
}
} 这里一个。
在文件的前面全部引用了命名空间。但问题依旧
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
{
这里没有实现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 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());
}
}
}
bool WithDraw(decimal amount);
decimal Balance
{
get;
}一个是被你写成了Withdraw (应该是WithDraw)
另一个是被你写成了Banlance (应该是Balance)还有
你根本就没有导入 System 命名空间,就写上了Console.WriteLine
没有实现接口中的成员啊
是你的大小写
在接口中是大写
bool WithDraw(decimal amount);
可是到了实现的类中就变成了小写了
public bool Withdraw(decimal amount)
public class SaverAccount : IBankAccount
{
void IBankAccount.PayIn(decimal amount)
//必须写明是实现哪个接口的方法
{
//省略
} bool IBankAccount.Withdraw(decimal amount)
{
//省略
}
decimal IBankAccount.Banlance
{
//省略
}
}