In the following code Visual Studio puts an error message on the word else. The specific error reads “Unexpected ‘else'”. What have I done wrong?
decimal AmountToAccrue;
string BillingDescription;
if (PromoPeriodEnd >= day)
AmountToAccrue = 0;
BillingDescription = "Subscription 30-day Promotional Period";
else
AmountToAccrue = subscription.Amount * ProratedPercentDue;
BillingDescription = "Subscription Fee";
You must use curly braces when you have multi-line
if‘s andelse‘s:Additional Information:
Without curly braces only the next statement, not line, is considered within the scope.
OK:
Not OK:
The “Not OK” example would be viewed by the compiler like this: