What is the meaning of underscore in visual basic? I have this code:
Private _isAuthenticated As Boolean
Is that the same as doing this?
Private isAuthenticated As Boolean
Or does adding the underscore to the front of the name do something special?
FYI: if you are looking at VB code prior to the .NET era (ie: VB6, of which there is a ton out there) the _ character did have special meaning in that it was a line continuation character. Variables or lines could not begin with an _
Example of VB6 use of _:
Dim str As String
str = "This is part one of a very long string" & _
"Notice that this is more text" & _
"AND SOME MORE"
I am pretty sure that in VB.NET the _ continues to function as a line continuation character, however the variable name restriction has obviously been lifted.
It's a convention. A leading _ often indicates that the variable is private to the class. This convention is commonly used in many different languages, not just VB.
In a similar sense, it also indicates that the variable is the local variable behind a property.
However it has no significant meaning to the compiler.
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