Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the use of defining a variable on a method inside a square brackets in VB.net?

Tags:

vb.net

I am looking at this method in vb.net and I am quite knew to vb.net. I am trying to understand why integer "[to]" and "[step] "is defined in square brackets ? Can some one please explain this to me. Why can these be defined just To/Step. I have attached the code below. Thanks in advance.

   ''' <summary>
    ''' Write to runtime output with loop information
    ''' Expected use when loop counter is incremented
    ''' </summary>
    Public Sub WriteToRuntimeOutput(counter As Integer, [to] As Integer, [step] As Integer)

        Dim message As New StringBuilder
        message.AppendFormat("Loop counter incremented. Loop {0}/{1}", counter, [to])
        If loopStep <> 1 Then
            message.AppendFormat(" Step {0}", [step])
        End If
        message.Append(".")
        return message.ToString()
    End Sub
like image 631
Nisha Avatar asked Jul 13 '26 11:07

Nisha


2 Answers

Square brackets are used to create a variable that has the same name as a keyword.

For example

Dim [Integer] As Integer

like image 140
Sameer Avatar answered Jul 15 '26 00:07

Sameer


I voted to close as duplicate but in fact the dup I linked works the other way around and does not really answer your question.

In your case : step and to are reserved keywords in VB. By surrounding them with square brakets you allow their use as variable names.

like image 33
Thomas G Avatar answered Jul 15 '26 00:07

Thomas G