Line Continuation in VB.NET

This article discusses the line continuation keyword and syntax in VB.NET language.
  • 6933

Line Continuation

Line continuation is needed when you want to spread out a single line of code into multiple lines. If you do not use a line continuation, you will get a syntax error in Visual Studio 2010.

line continuation is represented by a single underscore ("_ ") character with a combination of a white-space before the underscore and immediately followed by a whitespace. A line continuation must also have at least one character after the second whitespace, something like following:

SomeCharacter WhiteSpace UnderScore WhiteSpace SomeCharacter

The code snippet in Listing 1 creates a function and uses line continuation in function definition as well as in the code inside the function.

    Function LineContinuationSnippet(ByVal NumberOne As Integer, _

                                     ByVal NumberTwo As Integer) _

                                     As Integer

        If (NumberOne > NumberTwo Or _

            NumberOne = NumberTwo) Then

            Return NumberOne

        Else

            Return NumberTwo

        End If

 

    End Function

Listing 1

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.