Im sure this is simple but I've looked at it too long and I need an answer soon. I am new to C#. If I put GetCommission() within the struct I get
error CS0188: The 'this' object cannot be used before all of its fields are assigned to
outside the struct
error CS0038: Cannot access a non-static member of outer type 'Ex5._3.CommissionForm' via nested type 'Ex5._3.CommissionForm.salespersonFigures'
How do I get this done? Caveat: part of the assignment was that the commission be calculated in a method. None of the struct tutorials I've found deal with assigning one member based on the value of another. It should be kosher as the calculations only use static data. Right?
// Declare class variables and constants
private const decimal WEEKLY_BASE_SALARY = 250m;
private const decimal WEEKLY_QUOTA = 1000m;
private const decimal COMMISSION_RATE = .15m;
public struct salespersonFigures
{
// Fields
private string salesperson;
private decimal weeklySales;
private decimal commission;
private decimal pay;
// Constructor
public salespersonFigures(string name, decimal sales)
{
salesperson = name;
weeklySales = sales;
commission = GetCommission(sales); // error occurs at this line
pay = WEEKLY_BASE_SALARY + commission;
}
// Property
public decimal Sales
{
get
{
return weeklySales;
}
set
{
weeklySales = value;
}
}
public string Name
{
get
{
return salesperson;
}
set
{
salesperson = value;
}
}
// Method
public decimal GetCommission(decimal sales)
{
if (sales > WEEKLY_QUOTA)
return sales * COMMISSION_RATE;
else return 0m;
}
}