I am doing exercises in Head First C# book.
This code is supposed to be about encapsulation.
class DinnerParty
{
private int NumberOfPeople;
....
public void SetPartyOptions(int people, bool fancy) {
NumberOfPeople = people;
.....
}
public int GetNumberOfPeople() {
return NumberOfPeople;
}
}
In form1 class
public partial class Form1 : Form
{
DinnerParty dinnerParty;
public Form1()
{
InitializeComponent();
dinnerParty = new DinnerParty() {NumberOfPeople = 5 };
...
Is this suppose to work?
Visual Studio is showing me an error. (cannot access due to its protection level)
I am very new at this.
Thanks
No that is not supposed to work. I can’t see the book, so I can’t comment on the context. However:
Is a reasonable fix.