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

孤街醉人 提交于 2019-11-30 17:42:46
勿绮语

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.

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.

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

The _ (Underscore symbol) is used just because to notify that it is a Private variable.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!