I was look at somebody else's code and came across this piece of code
private string _deviceName { get; set; }
private string _deviceAlias { get; set; }
My thinking is that those automatic properties for private variables are unnecessary. Am I right in thinking so ?
My thinking is that those automatic properties for private variables are unnecessary. Am I right in thinking so ?
They aren't necessary, but they also don't really hurt anything. That being said, they don't really help anything either, as they're purely an implementation detail, so switching from a field to a property later wouldn't be a breaking change.
The only real reason to potentially do this would be if you knew, in the future, you would want custom logic on get or set, and you were using something that required the syntax to be different for properties, such as reflection. In this case, making them auto-properties now would prevent any need for changing the code later.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With