开发者

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


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜