I tried to do this:
public int Property {get; private set;}
It underlines the "set" and says this:
auto implemented accessor never set
It lets me compile but I am wondering if this effects anything or what is开发者_开发技巧 the deal with it?
What you have is valid syntax. You are getting the warning because nothing is setting a value to the property (ie. the setter is not being used anywhere).
If nothing is using the setter, then the property will always have its default value, in which case you should question the value of having the property there in the first place.
That's just a compiler warning not an error. It just tells you that you never use the setter inside the class.
The setter is private and compiler can check usage of it in the current class. The warning was generated because you never set a value into that property.
精彩评论