请教各位老师,这段代码为什么会提示无法实现接口成员?
提示是这个问题:“A.Me”不实现接口成员“A.Ibankio.have”。“A.Me.have”无法实现接口成员,因为它不是公共的
请教各位大神,这是为什么呢?
Console.WriteLine("您账户里面现有{0}元,您存了{1}元钱", have, a);
}
public void Out(decimal b)
{
if (b > have)
{
have -= b;
Console.WriteLine("您账户支出{0}元,剩余{1}元!", b, have);
}
else
Console.WriteLine("余额不足!");
}
/*public decimal c
{
get
{
return c;
}
set
{
if (have >= 0)
{
value = have;
c = value;
}
}
}*/
}
class Program
{
static void Main(string[] args)
{
Ibankio wo = new Me();
wo.have = 1000;
wo.In(10000);
wo.Out(12000);
}
}
}
[解决办法]
//我做了下小修改,能跑了,不知道能不能满足需求
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Error
{
interface Ibankio
{
decimal have //已有钱数
{
get;
set;
}
void In(decimal a);//存入钱数;
void Out(decimal b);//支出钱数;
/*decimal c//剩余钱数
{
get;
set;
}*/
}
class Me : Ibankio
{
private static decimal count;
public decimal have
{
get
{
return count;
}
set
{
if (count < 0)
{
Console.WriteLine("卡内余额不足");
}
}
}
public void In(decimal a)
{
count += a;
Console.WriteLine("您账户里面现有{0}元,您存了{1}元钱", have, a);
}
public void Out(decimal b)
{
if (b < count)
{
count -= b;
Console.WriteLine("您账户支出{0}元,剩余{1}元!", b, have);
}
else
Console.WriteLine("余额不足!");
}
/*public decimal c
{
get
{
return c;
}
set
{
if (have >= 0)
{
value = have;
c = value;
}
}
}*/
}
class Program
{
static void Main(string[] args)
{
Ibankio wo = new Me();
wo.have = 1000;
wo.In(10000);
wo.Out(12000);
}
}
}