开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜