Вот мой код ниже:
Код класса
Код: Выделить всё
public class Employee
{
private int hoursWorked;
private double ratePerHour;
// Property structures (getter/setter methods)
public int propHoursWorked
{
get { return hoursWorked; }
set { hoursWorked = value; }
}
public double propRatePerHour
{
get { return ratePerHour; }
set { ratePerHour = value; }
}
// Default Constructor
public Employee()
{
propHoursWorked = 0;
propRatePerHour = 0.00;
}
// Parameterised Constructor
public Employee(int hw, double rph)
{
propHoursWorked = hw;
propRatePerHour = rph;
}
// Methods
public double calcBase()
{
return (propRatePerHour * propHoursWorked);
}
public double calcTax()
{
return (calcBase() * 0.15);
}
public double calcNet()
{
return (calcBase() - calcNet());
}
}
Код: Выделить всё
private void btnCalculate_Click(object sender, EventArgs e)
{
/// Declare variables
int HoursWorked;
double RatePerHour, BaseSalary=0, TaxDue=0, NetPay=0;
// Input
HoursWorked = int.Parse(txtHoursWorked.Text);
RatePerHour = double.Parse(txtRatePerHour.Text);
// Processing
// Create an object using the class as a blueprint
// Method 1 - Using the Default Constructor
Employee objE = new Employee(HoursWorked, RatePerHour);
BaseSalary = objE.calcBase();
TaxDue = objE.calcTax();
NetPay = objE.calcNet();
// Output
lblBaseSalary.Text = BaseSalary.ToString("C");
lblTax.Text = TaxDue.ToString("C");
lblNetPay.Text = NetPay.ToString("C");
}
Вот сообщение об ошибке. Он просто срабатывает в случайных местах класса
Подробнее здесь: https://stackoverflow.com/questions/790 ... was-thrown