K
Kavvy
How come a lot of the examples I have seen on the net define accessor pairs
within a class, and then only ever use the accessor outside the class? When
used within the class the variable is accessed directly.
Is there something I'm missing about this? To reduce code re-writing it is
(I thought) standard practice to use accessor pairs in the class that
defines them as well as outside.
This becomes apparent if you need to perform checks on a new value before
assigning it to the variable. If you have 10 places where the variable is
directly accessed within the class then you would have 10 places to update
your code. If using an accessor pair then you only have 1 place to update
you code.
Correct me if I'm wrong or missing something about C# accessor pairs.
Rich.
within a class, and then only ever use the accessor outside the class? When
used within the class the variable is accessed directly.
Is there something I'm missing about this? To reduce code re-writing it is
(I thought) standard practice to use accessor pairs in the class that
defines them as well as outside.
This becomes apparent if you need to perform checks on a new value before
assigning it to the variable. If you have 10 places where the variable is
directly accessed within the class then you would have 10 places to update
your code. If using an accessor pair then you only have 1 place to update
you code.
Correct me if I'm wrong or missing something about C# accessor pairs.
Rich.