Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meaning of _ underscore as a variable prefix in VB.net

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?

like image 644
StealthRT Avatar asked Dec 15 '11 03:12

StealthRT


2 Answers

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.

like image 97
codechurn Avatar answered Sep 20 '22 19:09

codechurn


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.

like image 22
勿绮语 Avatar answered Sep 21 '22 19:09

勿绮语