Reputation: 47169
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 the property as such.
Me._MyProperty = "BlahBlah"
Is there an equivalent mechanism in C# ?
Upvotes: 3
Views: 3129
Reputation: 25258
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;}
Upvotes: 8
Reputation: 9298
In C# you cannot refer to the underlying variable of auto implemented properties directly.
Upvotes: 5