Auto Generated Properties in C #

In VB.NET in the class, you can do the following.

Public Property MyProperty As String

At this point, a getter and setter is automatically created for you, and you can refer to a variable defined by the property as such.

Me._MyProperty = "BlahBlah"

Is there an equivalent mechanism in C #?

+3
source share
2 answers
public string MyProperty {get; set;}

By default, they are publicly accessible accessories, you can make one of them private, like this:

public string MyProperty {get; private set;}
+8
source

In C #, you cannot directly reference the base variable of automatically implemented properties.

+5
source

Source: https://habr.com/ru/post/1795935/


All Articles