I am trying to make a method in a new class that I made...
public void CalcDrinks(bool HealthOption)
{
if (HealthOption)
{
CostOfBeverage = 5M;
}
else
{
CostOfBeverage = 20M;
}
}
And I keep getting a red squiggly under the void saying... "expected class, delegate, enum, interface or struct error"
I'm not sure what I am missing...
You would get that precisely that error if the method is declared outside of a class.
namespace Blah
{
public void CalcDrinks(bool HealthOption)
{
if (HealthOption)
{
CostOfBeverage = 5M;
}
else
{
CostOfBeverage = 20M;
}
}
}
In this snippet, there is no class definition to be seen. Fix it to the below and see that it compiles.
public class Foo
{
private decimal CostOfBeverage;
public void CalcDrinks(bool HealthOption)
{
if (HealthOption)
{
CostOfBeverage = 5M;
}
else
{
CostOfBeverage = 20M;
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With