When running code analysis on my project, I receive the following message:
CA1051 : Microsoft.Design : Because field 'ClassName.VarName' is visible outside of its declaring type, change its accessibility to private and add a property, with the same accessibility as the field has currently, to provide access to it.
To resolve this, I can change the following line:
Public VarName As String
to this:
Public Property VarName As String
I don't understand why the Property keyword is so important in this particular case. Can anyone provide an explanation as to why changing this member to a Property makes a significant difference to code analysis? Am I doing something wrong?
Using 'Property' allows you to define public access methods for your variables instead of making those variables public. See here for a good explanation: http://msdn.microsoft.com/en-us/library/65zdfbdt%28v=vs.71%29.aspx
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