Could someone tell me the difference between
static public
public static
and
private int _myin = 0
public int MyInt
{
get{ return _myInt; }
private set {_myInt = value; }
}
the private set part is what I want to know
The first 2 are no different, you can order the modifiers however you like, though this is more common:
public static
The second, it means that the property can only be set within the class, but can get gotten publicly, by anyone with a reference.
E.g. this only works inside the class:
MyInt = 123;
But this works anywhere:
int Temp = MyClass.MyInt;
And as another example, this would fail:
var mc = new MyClass();
mc.MyInt = 123; //this won't compile, it's not a public setter
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With