Can automatically implemented properties have their own set?

I tried to do this:

public int Property {get; private set;}

He emphasizes “recruitment” and says the following:

an automatically implemented accessory is never installed

This allows me to compile, but I wonder if it affects anything or what is connected with it?

+5
source share
3 answers

You have valid syntax. You get a warning because nothing sets a value for the property (i.e., the Setter is not used anywhere).

If nothing is used by the installer, the property will always have a default value, in which case you should ask if you need to have the property there.

+11
source

, . , .

+4

The typesetter is private, and the compiler can test its use in the current class. A warning was generated because you never set a value to this property.

+1
source

All Articles