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.
Printable View
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.
Nothing, in VB.NET.
Blah I hate how there is 10 ways to do the same thing now.... Thanks for the quick response!
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.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.vb.net Code:
Dim start As Date = Date.Today Dim [end] As Date = start.AddDays(10)
That was most helpful. Thanks!
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.