KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I just realized that the C# property construct can also be used with a private access modifier: private string Password { get; set; } Although this is technically interesting, I can't imagine when I would use it since a private field involves even less ceremony : private string _password; and I can't imagine when I would ever need to be able to internally get but not set or set but not get a private field: private string Password { get; } or private string Password { set; } but perhaps there is a use case with nested / inherited classes or perhaps where a get/set might contain logic instead of just giving back the value of the property, although I would tend to keep properties strictly simple and let explicit methods do any logic, e.g. GetEncodedPassword() . Does anyone use private properties in C# for any reason or is it just one of those technically-possible-yet-rarely-used-in-actual-code constructs?
Tags (comma-separated)
Save Edits
Cancel