这是一堂课 为什么在MySales上获取和设置,以及theUnits使我的程序无法正常工作? 香港专业教育学院试图评论它,删除它,什么都行不通。我无法弄清楚它为什么不起作用
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace project_5
{
public class salesinvoice
{
private double Netmoney;
private double Newmoney;
private double StateValue;
private double LocalValue;
private double stateTax = 0.0745;
private double localTax = 0.025;
public double theUnits
{
get
{
return theUnits;
}
set
{
theUnits = value;
}
}
public double MySales
{
get
{
return MySales;
}
set
{
MySales = value;
}
}
public salesinvoice()
{
Netmoney = 0;
Newmoney = 0;
}
public double Getmoney()
{
return Netmoney;
}
public double GetNewmoney()
{
return Newmoney;
}
public double GetStateValue()
{
return StateValue;
}
public double GetLocalValue()
{
return LocalValue;
}
public void NetSales()
{
Netmoney = theUnits * MySales;
}
public void StateTax()
{
StateValue = Netmoney * stateTax;
}
public void LocalTax()
{
LocalValue = Netmoney * localTax;
}
public void GrossSales()
{
Newmoney = Netmoney + StateValue + LocalValue;
}
}
}
答案 0 :(得分:0)
如果您希望C#为您生成访问者,请使用
public double theUnits { get; set;}
如果你想自己处理它们,你需要一个像这样的私人副本:
private double _theUnits;
public double theUnits {
get { return this._theUnits; }
set { this._theUnits = value; }
}