No difference if you use it the way you do. Now, imagine instead of
get { return Number; }
you write something else:
internal int MyNumber {
get {
int readValue = ComplexCalculation();
MyHistory.Add(readValue);
return readValue;
}
}
int ComplexCalculation() { }
System.Collection.Generic<int> MyHistory = new System.Collection.Generic<int>();
That was the use of property
getter. More typical use of the
setter:
internal int MyNumber {
get { return Number; }
set {
Number = value;
MyForm.MyLabel.Text = Number;
}
}
So, this is the core idea about properties:
interface like that of fields, functionality like that of methods, with possible side effect. The methods are actually only getter or setter or both, but the body is arbitrary. Also, like methods the property can be
static or
instance one, that is without or with access to "this" parameter (reference to the instance of a declaring type). I also replaced your
public
with
internal
. So far, I see no justification for
public
. You really want to give the minimal possible access. Read about it:
http://msdn.microsoft.com/en-us/library/ba0a1yw2%28v=VS.100%29.aspx[
^].
Note, I replaced you
INumber
with
MyNumber
. Don't violate good Microsoft naming conventions. First style of naming is reserved for
interfaces.
Now, this is a time for you to say: "Aha!". Come on!
—SA