简体   繁体   中英

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.

Eg 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM