What are square brackets used for?

Hello all, just curious on this.

What's the difference between something like

Dim strName as String, and
Dim strName as [String]

And where/why would you use [ ] if there is a difference

Thank you in advance.


Answer this question

What are square brackets used for?

  • sth2n

    They are used for reserved words.  Stop is a reserved word.  If you were to do the following:


    Public Sub Stop()
    _Stopped = True
    End Sub

     


    You would get a compile error.  Adding brackets around Stop allows you to use it.  In vb.classic this wasn't available.

    Cheers,
    Chid
     
    
    
    
    

  • Ohadr2

    Ok I understand that, it makes sense but I don't see why you'd use it in this context then:

    Dim strName as String
    strName = [String].Empty

    I've seen it used like that in the ASP.NET starter kits. Any ideas why it's not this instead:

    strName = String.Empty

    Thanks for your help Smile

  • LFerg

     elf_sander wrote:
    It is to create variable which is already used like stop...



    public enum playstate
    play
    pause
    [stop]
    next
    end enum

     


    I don't get it, sorry, but I too don't know about this [] thing. And Google is useless.

  • Excelerator

    It is to create variable which is already used like stop...



    public enum playstate
    play
    pause
    [stop]
    next
    end enum

     

  • Carriage1

    There is no difference.  I have found that some of the C# to VB converters will put brackets in where they don't really belong.  I recently converted a project and it changed all references to the Text property of the object to [Text]. Doesn't hurt anything, just a bit of overkill. That might explain the code in the starter kits.

    Chid

  • What are square brackets used for?