[英]Are Properties technically considered nonstatic in C#?
My textbook is referring to the this reference and it first implies that a property is somewhat static and does not store one with each object, but one for the entire class. 我的教科书是指这个引用,它首先暗示一个属性有点静态,并且不会为每个对象存储一个属性,而是为整个类存储一个属性。 Then later it says that a property is nonstatic.
后来它说房产是非静态的。 I am really confused.
我真的很困惑。 What is it?
它是什么?
A property can be both static and non-static you decide which by using the static
keyword. 通过使用
static
关键字,您可以决定静态和非静态属性。
public static int StaticProperty {get; set; }
public int InstanceProperty {get; set; }
On a side note, a property is actually two methods (or just one if you only implement the set
or get
). 另一方面,属性实际上是两种方法(如果只实现
set
或get
则只有一种方法)。
public int MyProperty {get; set; }
is equivalent to 相当于
public void set_MyProperty(int value);
public int get_MyProperty();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.