Is it possible to hide a field (or just manipulate / hide from autocomplete) in its class?

I have a (fairly) complex file with the usual combination of components.

I have a field (called keyloaded) and a related property (called keyloaded).

While working inside a class, I accidentally manipulated a field instead of a property.

Most likely, this is because I'm still a little new to all of this (I’m checking the three now), but this is already a personal field and works great outside the class. Is there something simple I can do that will remove it from Autocomplete?

And if not, what are the best practices for this situation?

While I was writing this question, I suddenly remembered in my book, they spoke about underscores ... Is it just the best solution - to remove it from sight?

+5
source share
3 answers

Like Brian and Kobek, you can simply start your fields with an underscore. But if you really want to hide the method / field / property, you can set the attribute as shown. This will prevent the method / field / property from being displayed in intellesense. However, the member will still be available.

<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
+6
source

I use underscore as a prefix for private fields, for example "_keyloaded". If the property only sets and receives the field, consider creating an automatic property, for example:

public bool Keyloaded { get; set; }
+2
source

I think Microsoft's current code syntax standards say that either fields or properties can be Pascal Case. However, I have always adhered to the agreement that fields should begin with an underscore. Change keyloaded to _keyloaded. I think it will be much easier for you to identify the difference between fields, properties, and locales in this way.

+1
source

All Articles