brackets around types?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brian Henry

    #1

    brackets around types?

    i was just looking at the tcplistener example on the MSDN docs and saw this

    Dim bytes(1024) As [Byte]
    Dim data As [String] = Nothing

    the data types ar ein brackets, what is the significance of the brackets?
    and when i type them into vb.net 2003 the brackets remove themself... why
    are they there, what do they do? thanks!


  • Armin Zingler

    #2
    Re: brackets around types?

    "Brian Henry" <NOSPAMbrianiup @adelphia.net> schrieb[color=blue]
    > i was just looking at the tcplistener example on the MSDN docs and
    > saw this
    >
    > Dim bytes(1024) As [Byte]
    > Dim data As [String] = Nothing
    >
    > the data types ar ein brackets, what is the significance of the
    > brackets? and when i type them into vb.net 2003 the brackets remove
    > themself... why are they there, what do they do? thanks![/color]

    In your example the brackets are superfluous.

    To use reserved keywords as identifiers, the brackets must be used to
    distinguish between the identifier and the keyword:

    dim [String] As String

    public sub [Stop]
    end sub

    see also:
    http://msdn.microsoft.com/library/en...amesInCode.asp


    --
    Armin




    Comment

    • Fergus Cooney

      #3
      Re: brackets around types?

      Hi Brian,

      In your examples:

      Dim bytes(1024) As [Byte]
      Dim data As [String] = Nothing

      they do absolutely nothing (which is why they get removed without loss).

      In this, though:

      Dim [Byte](1024) As Byte
      Dim [String] As String = Nothing
      [String] = "Poor choice of variable name"

      the [] around the names allows you to use a reserved word. The compiler
      won't object because you're telling it that you know what you're doing.

      Very few people would want to call their variables Byte or String but it's
      allowed when [] is used.

      Here's a decent example:
      Class StopWatch : Inherits Clock
      Public Sub Start
      'Note the start time.
      End Sub

      Public Sub [Stop]
      'Record the time taken.
      End Sub
      End Class

      'Stop' is a reserved word but it's more than reasonable that a StopWatch
      has a Stop method!! So it needs the [] around it in the declaration.

      However, in use, unlike the [Byte] and [String] above, you wouldn't need
      the [] with Stop because it will be partnered with a StopWatch object.

      oStopWatch.Star t
      'Do something
      oStopWatch.Stop
      Console.WriteLi ne (oStopWatch.Ela psed ("ms"))

      For the compiler there's no possibilty that the 'Stop' in oStopWatch.Stop
      is a reserved word so the [] are not needed.

      Regards,
      Fergus

      --
      (Please ignore this - there's a feud going on)
      =============== =============== =============== =====
      Quote of the day
      Herfried:
      I don't need/want human interaction.
      =============== =============== =============== =====


      Comment

      • Brian Henry

        #4
        Re: brackets around types?

        makes me kinda wonder why MSDN put them in there documentation for
        tcplistener...


        "Fergus Cooney" <filter@post.co m> wrote in message
        news:OHmBmYupDH A.708@TK2MSFTNG P10.phx.gbl...[color=blue]
        > Hi Brian,
        >
        > In your examples:
        >
        > Dim bytes(1024) As [Byte]
        > Dim data As [String] = Nothing
        >
        > they do absolutely nothing (which is why they get removed without[/color]
        loss).[color=blue]
        >
        > In this, though:
        >
        > Dim [Byte](1024) As Byte
        > Dim [String] As String = Nothing
        > [String] = "Poor choice of variable name"
        >
        > the [] around the names allows you to use a reserved word. The[/color]
        compiler[color=blue]
        > won't object because you're telling it that you know what you're doing.
        >
        > Very few people would want to call their variables Byte or String but[/color]
        it's[color=blue]
        > allowed when [] is used.
        >
        > Here's a decent example:
        > Class StopWatch : Inherits Clock
        > Public Sub Start
        > 'Note the start time.
        > End Sub
        >
        > Public Sub [Stop]
        > 'Record the time taken.
        > End Sub
        > End Class
        >
        > 'Stop' is a reserved word but it's more than reasonable that a[/color]
        StopWatch[color=blue]
        > has a Stop method!! So it needs the [] around it in the declaration.
        >
        > However, in use, unlike the [Byte] and [String] above, you wouldn't[/color]
        need[color=blue]
        > the [] with Stop because it will be partnered with a StopWatch object.
        >
        > oStopWatch.Star t
        > 'Do something
        > oStopWatch.Stop
        > Console.WriteLi ne (oStopWatch.Ela psed ("ms"))
        >
        > For the compiler there's no possibilty that the 'Stop' in[/color]
        oStopWatch.Stop[color=blue]
        > is a reserved word so the [] are not needed.
        >
        > Regards,
        > Fergus
        >
        > --
        > (Please ignore this - there's a feud going on)
        > =============== =============== =============== =====
        > Quote of the day
        > Herfried:
        > I don't need/want human interaction.
        > =============== =============== =============== =====
        >
        >[/color]


        Comment

        • Fergus Cooney

          #5
          Re: brackets around types?

          Hi Brian,

          I have the 2001 MSDN Help at home and there's an old version of that
          code with [Byte] but the new one on the MSDN has more of them. Maybe
          it was a translation from some C# by someone who wasn't quite sure? It's
          certainly wierd. I mailed them some feedback from the link at the bottom.

          Regards,
          Fergus


          Comment

          • Herfried K. Wagner [MVP]

            #6
            Re: brackets around types?

            * "Brian Henry" <NOSPAMbrianiup @adelphia.net> scripsit:[color=blue]
            > i was just looking at the tcplistener example on the MSDN docs and saw this
            >
            > Dim bytes(1024) As [Byte]
            > Dim data As [String] = Nothing
            >
            > the data types ar ein brackets, what is the significance of the brackets?
            > and when i type them into vb.net 2003 the brackets remove themself... why
            > are they there, what do they do?[/color]

            See:

            <http://msdn.microsoft. com/library/en-us/vbcn7/html/vaconkeywordsas controlnamesinc ode.asp>

            --
            Herfried K. Wagner
            MVP · VB Classic, VB.NET
            <http://www.mvps.org/dotnet>

            <http://www.plig.net/nnq/nquote.html>

            Comment

            • Herfried K. Wagner [MVP]

              #7
              Re: brackets around types?

              * "Brian Henry" <NOSPAMbrianiup @adelphia.net> scripsit:[color=blue]
              > makes me kinda wonder why MSDN put them in there documentation for
              > tcplistener...[/color]

              For example in the docs for 'TcpListener.Ac ceptSocket' they don't make
              sense.

              --
              Herfried K. Wagner
              MVP · VB Classic, VB.NET
              <http://www.mvps.org/dotnet>

              <http://www.plig.net/nnq/nquote.html>

              Comment

              • Brian Henry

                #8
                Re: brackets around types?

                that is what threw me off... the fact it was around the data type, i knew
                about reserved words with brackets because of working with sql server and
                similar circumstances.. . but brackets around a data type just was like what
                the hehe..

                thanks everyone


                "Fergus Cooney" <filter@post.co m> wrote in message
                news:Okou82upDH A.2268@TK2MSFTN GP12.phx.gbl...[color=blue]
                > Hi Brian,
                >
                > I have the 2001 MSDN Help at home and there's an old version of that
                > code with [Byte] but the new one on the MSDN has more of them. Maybe
                > it was a translation from some C# by someone who wasn't quite sure? It's
                > certainly wierd. I mailed them some feedback from the link at the bottom.
                >
                > Regards,
                > Fergus
                >
                >[/color]


                Comment

                Working...