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

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.


Many use the underscore prefix for field members of the class. These variables should be scoped as Private. This is just a convention however.


At the end of a line, it can be used to split code across multiple lines if it's preceded by a space & the very next character is the new line (_ is the last symbol on the line & followed by a space.

see http://msdn.microsoft.com/en-us/library/ba9sxbw4.aspx