I have a Console app with the following code:
using System;
namespace HeadfirstPage210bill
{
class Program
{
static void Main(string[] args)
{
CableBill myBill = new CableBill(4);
Console.WriteLine(myBill.iGotChanged);
Console.WriteLine(myBill.CalculateAmount(7).ToString("£##,#0.00"));
Console.WriteLine("Press enter to exit");
Console.WriteLine(myBill.iGotChanged);
Console.Read();
}
}
}
The class CableBill.cs is the following:
using System;
namespace HeadfirstPage210bill
{
class CableBill
{
private int rentalFee;
public CableBill(int rentalFee) {
iGotChanged = 0;
this.rentalFee = rentalFee;
discount = false;
}
public int iGotChanged = 0;
private int payPerViewDiscount;
private bool discount;
public bool Discount {
set {
discount = value;
if (discount) {
payPerViewDiscount = 2;
iGotChanged = 1;
} else {
payPerViewDiscount = 0;
iGotChanged = 2;
}
}
}
public int CalculateAmount(int payPerViewMoviesOrdered) {
return (rentalFee - payPerViewDiscount) * payPerViewMoviesOrdered;
}
}
}
The console is returning the following:

What I can not see is when payPerViewDiscount is set to 0. Surely this can only happen when the Discount property is set but if the property Discount is called then the variable iGotChanged should be returning 1 or 2, but it seems to stay on 0. Because it is type int is there a default value for payPerViewDiscount of 0?
yes the default value of int is
0you can check using thedefaultkeywordtwill hold0