ASP.NET类问题

时间:2010-07-22 22:38:48

标签: c# asp.net

有人可以告诉我

之间的区别
static public
public static

private int _myin = 0
public int MyInt
{
    get{ return _myInt; }
    private set {_myInt = value; }
}

私人设定部分是我想知道的

1 个答案:

答案 0 :(得分:10)

前两个没有什么不同,您可以随意订购修饰符,但这更常见:

public static

第二个,这意味着该属性只能在类中设置,但可以被任何有参考的人公开。

E.g。这只适用于班级:

MyInt = 123;

但这可以在任何地方使用:

int Temp = MyClass.MyInt;

另一个例子是,这会失败:

var mc = new MyClass();
mc.MyInt = 123; //this won't compile, it's not a public setter