首页 > 代码库 > c#接口定义与应用
c#接口定义与应用
public interface IBankAccount //只能加public修饰符,或者什么都不加
{
void Playin(decimal money); //函数前不加任何修饰符号
bool WithDrew(decimal money);
decimal Account
{
get;
}
}
class aa:IBankAccount
{
private decimal banance;
public void Playin(decimal money)//前面必须只能加public修饰符
{
banance+=money;
}
public bool WithDrew(decimal money)
{
if (banance >= money)
{
banance -= money;
return true;
}
else return false;
}
public decimal Account
{
get
{
return banance;
}
}
public override string ToString()//系统内的tostring为虚基类,可以重写
{
return String.Format("{0,6:c}",banance);
}