ONYX
ONYX

Reputation: 5859

ASP.NET Classes Question

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

Upvotes: 4

Views: 61

Answers (1)

Nick Craver
Nick Craver

Reputation: 630399

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

Upvotes: 10

Related Questions