Autogenerated properties in C#
In VB.NET it is possible to do the following in a class.
Public Property MyProperty As String
At this point a getter and setter is automagically created for you and you can refer to variable defined by t开发者_JAVA技巧he property as such.
Me._MyProperty = "BlahBlah"
Is there an equivalent mechanism in C# ?
public string MyProperty {get; set;}
by default they are both public accessors, you can make one of them private like this:
public string MyProperty {get; private set;}
In C# you cannot refer to the underlying variable of auto implemented properties directly.
精彩评论