Results 1 to 6 of 6

Thread: [RESOLVED] [2005] Arrays...

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2007
    Posts
    66

    Resolved [RESOLVED] [2005] Arrays...

    I was wondering if someone could clarify something for me.

    When declaring an array is there any difference with these:

    Dim sendBytes As [Byte]()

    Dim sendBytes() as Byte

    What's the [] for in the first example?

    Thanks in advance.

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: [2005] Arrays...

    Nothing, in VB.NET.
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2007
    Posts
    66

    Re: [2005] Arrays...

    Blah I hate how there is 10 ways to do the same thing now.... Thanks for the quick response!

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] [2005] Arrays...

    When you use square brackets like that you are telling the compiler to NOT treat the word as a language key word. Note that if you don't use the brackets the word Byte will turn blue, indicating that it is a VB.NET key word. Thus you are specifying the VB.NET Byte data type. If you do use the brackets then you are specifying the System.Byte structure as the type, not the inbuilt Byte data type.

    Having said that, the inbuilt Byte data type is implemented using the System.Byte type so there really is no difference in the end. There are other situations where the brackets are more menaingful, e.g.
    vb.net Code:
    1. Dim start As Date = Date.Today
    2. Dim [end] As Date = start.AddDays(10)
    In that case you have to use the square brackets in order to use "end" as an identifier or else it will be interpreted as the "End" key word and produce a syntax error. Note that in that situation the name of the variable is still "end", not "[end]". The brackets are not part of the identifier itself, but just indicate that it is an identifier and not a key word.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jun 2007
    Posts
    66

    Re: [RESOLVED] [2005] Arrays...

    That was most helpful. Thanks!

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: [RESOLVED] [2005] Arrays...

    Hunh, I knew about that in SQL, but didn't realize it had made it into VB.

    In general, it's a bad idea to use it just because of the potential confusion that can arise. However, if you have to you have to.
    My usual boring signature: Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width