I have a (quite) complicated file with the usual mix of components.
I have a field (called keyloaded
) and a linked property (called Keyloaded
).
Whilst working within the class, I accidentally directly manipulated the field instead of the property.
It most likely is because I am still quite a bit new to all of this (I triple check now!), however, this is already a private field and outside of working with the class works great. Is there just something simple I can do that will remove it from Autocomplete?
And if not, what are the best practices for a similar situation?
Whilst writing this question, I suddenly remembered in my book, they said about underscores... Is this just the best solution - to put it out of sight?
Like Brian and KBoek mentioned you can just start your fields with an underscore. But if you really want to hide a method/field/property you can set the attribute as shown. This will prevent the method/field/property from being shown in intellesense. However, The member will still be accessible.
<System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)> _
Public Property HiddenProperty()
Get
return _hiddenProperty
End Get
Set (value as object)
_hiddenProperty = value
End Set
End Sub
I use underscore as a prefix to private fields, like "_keyloaded". If the property only sets and gets the field, consider creating an auto-property like this:
public bool Keyloaded { get; set; }
I think Microsoft's current Code Syntax standards say that either Fields Or Properties can be Pascal Case. However, I have always stuck with the convention that fields should begin with an underscore. Change keyloaded to _keyloaded. I think you will find it much easier to identify the difference between fields, Properties, and locals this way.
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