Internal use of Properties or local variables?

  • Thread starter Thread starter AA
  • Start date Start date
A

AA

I have a class, the class has properties and methods, Properties have his
private variables
So, from my local method what is better to use? the property or the variable
 
AA said:
I have a class, the class has properties and methods, Properties have his
private variables
So, from my local method what is better to use? the property or the variable

I personally prefer using the property wherever possible. Indeed, I
wish in C# there was a way of hiding the variable from everything other
than the properties, to ensure access goes through them. That way you
can guarantee that if you put a breakpoint in the setting property (for
instance) you can always see when the value changes. You can guarantee
that any consistency checks you have are always carried out, etc.
 
Back
Top