Not really understanding Backing Fields with custom get; and set;
Hey all.
I'm getting a little confused with backing fields with custom getters and setters. I have the following code
The thing that's confusing me is, how they're assigned within the constructor. I'll try to explain as best as I can.
If in the constructor,
Is it because of how
For example; if 5 is used on initialization of the object, the setter is setting _age to 5, then as we're getting
Sorry if I've explained this poorly...
I'm getting a little confused with backing fields with custom getters and setters. I have the following code
The thing that's confusing me is, how they're assigned within the constructor. I'll try to explain as best as I can.
If in the constructor,
_name = name, which is using the backing field (I assume), how come for the age I need to do Age = age and not _age = age?, it feels like _age isn't being used at all. Is it because of how
_age is used in the set why Age is used in the constructor?For example; if 5 is used on initialization of the object, the setter is setting _age to 5, then as we're getting
_age via Age, this is why Age is used in the constructor and not _age? I hope that's correct! Sorry if I've explained this poorly...