You need to understand that,
private int confirmed { get; set; }
will be expanded to a set of private
methods with a private
backing field,
private int _confirmed;
private int confirmed_get()
{
return this._confirmed;
}
private void confirmed_set(int value)
{
this._confirmed = value;
}
Thus, marking the property private
makes both the accessor and the mutator also private, which is why you cannot access them outside of the class. Also, these methods are not accessible at compile time, so calling instance.confirmed_get()
is not permitted, only instance.confimed
both to read and write to the property.
What you might want is to declare it public
,
public int confirmed { get; set; }
where the behavior is similar (the field still is private
), but both method are now public
. As others have mention you can individually modify the get
and set
for readonly
or writeonly
type of behavior,
public int confirmed { get; private/protected set; }
or
public int confirmed { private/protected get; set; }
And one last thing, you should get into the habit of using camel case for propeties, e.g. Confirmed
and lower camel case for fields, e.g. confirmed
(some might even do _confirmed
). It is a popular naming conventions to distinguish the two types, especially for consumers of the class.