[英]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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.