Answered by:
Array of byte

Question
-
Hi
What is the difference between;
Dim x As Byte()
and
Dim x() As Byte
Thanks
Regards
Tuesday, August 9, 2016 2:22 PM
Answers
-
Short answer, nothing. The both declare the variable x to be an array of byte that is set to Nothing.
The difference is important if declaring an array that has elements, i.e. when a bounds is defined. You can do this
Dim x(3) As Integer
You can't do this,
Dim x As Integer(3)
My preference is to use the first example because it works in all cases.
"Those who use Application.DoEvents() have no idea what it does and those who know what it does never use it." - MSDN User JohnWein Multics - An OS ahead of its time.
- Proposed as answer by Frank L. Smith Tuesday, August 9, 2016 3:00 PM
- Edited by dbasnett Tuesday, August 9, 2016 3:37 PM
- Marked as answer by Herro wongMicrosoft contingent staff Thursday, August 18, 2016 9:47 AM
Tuesday, August 9, 2016 2:50 PM
All replies
-
Short answer, nothing. The both declare the variable x to be an array of byte that is set to Nothing.
The difference is important if declaring an array that has elements, i.e. when a bounds is defined. You can do this
Dim x(3) As Integer
You can't do this,
Dim x As Integer(3)
My preference is to use the first example because it works in all cases.
"Those who use Application.DoEvents() have no idea what it does and those who know what it does never use it." - MSDN User JohnWein Multics - An OS ahead of its time.
- Proposed as answer by Frank L. Smith Tuesday, August 9, 2016 3:00 PM
- Edited by dbasnett Tuesday, August 9, 2016 3:37 PM
- Marked as answer by Herro wongMicrosoft contingent staff Thursday, August 18, 2016 9:47 AM
Tuesday, August 9, 2016 2:50 PM -
Hi
What is the difference between;
Dim x As Byte()
and
Dim x() As Byte
Thanks
Regards
Preference - the empty parentheses tell it all it needs to know.Some people succeed because they were destined to, but most people succeed because they were determined to.
Tuesday, August 9, 2016 3:00 PM -
Be aware your kind of code is from the days basic was a learning tool.
Because of the fact that an array is immutable the consequence is that if the dimension of an array is changed it is completely copied in memory.
A fixed array like in the sample from Dbasnett which does not change in memory have their purposes.
Better use an arraylist of what is even better its successor the generic list.
Success
Cor- Edited by Cor Ligthert Tuesday, August 9, 2016 5:40 PM
Tuesday, August 9, 2016 5:40 PM -
Be aware your kind of code is from the days basic was a learning tool.
Because of the fact that an array is immutable the consequence is that if the dimension of an array is changed it is completely copied in memory.
A fixed array like in the sample from Dbasnett which does not change in memory have their purposes.
Better use an arraylist of what is even better its successor the generic list.
Success
Cor
An ArrayList is NOT generic.
An ArrayList is NOT type-safe.
If I say anything more you'll take it personally (which is fine by me) but your statements are senseless.
A fixed array of byte is likely from reading bytes from a stream. They are small and do the job MUCH better than than any other way.
Some people succeed because they were destined to, but most people succeed because they were determined to.
Tuesday, August 9, 2016 5:47 PM -
Be aware your kind of code is from the days basic was a learning tool.
Because of the fact that an array is immutable the consequence is that if the dimension of an array is changed it is completely copied in memory.
A fixed array like in the sample from Dbasnett which does not change in memory have their purposes.
Better use an arraylist of what is even better its successor the generic list.
Success
Cor
An ArrayList is NOT generic.
An ArrayList is NOT type-safe.
If I say anything more you'll take it personally (which is fine by me) but your statements are senseless.
A fixed array of byte is likely from reading bytes from a stream. They are small and do the job MUCH better than than any other way.
Some people succeed because they were destined to, but most people succeed because they were determined to.
Frank,
The Generic List was created when the arraylist had always to be casted and that did cost a lot of time.
It is as type safe as the dataset which suffers from the same problems from those days and in fact a reason why persons want to use Linq with Option Infer in database handling. (Linq to entities and Linq to SQL)
However, there was created a so called generic dataset (although that was generated and not done with inferring in Visual Studio .Net). Nevertheless see I thousand times given by persons samples with a DataSet and Datatable in this forum without any message from Frank about type safety.
I don't see where I wrote that an arraylist is type safe, moreover, I told that it is better to use a generic list.
I don't know what you want to say with your last sentence, it is also not different from what I wrote.
Use those small cups next time when you drink coffee.
Success
Cor- Edited by Cor Ligthert Tuesday, August 9, 2016 6:15 PM
Tuesday, August 9, 2016 6:14 PM -
Use those small cups next time when you drink coffee.
Success
Cor
Talk to me in a demeaning way ever again and we'll get right back into it again - you always lose. I see to it.
*****
Tell me why it's a "better way" Cor?
What is type safety? Let's do that first. Tell me what's meant by that? What is it - then let's talk about generics - why is that type safe?
Then I'll show you why an ArrayList is neither.
If you don't know the source - and neither do I - then tell me why something that has such an overhead is "better" Cor?
Where do you normally see byte() used? Right - streams (as from reading a file) or a memorystream. Where else?
I'm stumped as to where else, Duane is correct, and none of this has to do with what the OP even asked which has to do with syntax!
Some people succeed because they were destined to, but most people succeed because they were determined to.
Tuesday, August 9, 2016 6:19 PM -
-
Better use an arraylist of what is even better its successor the generic list.
Was there a typo error in that statement?
Was it meant to read like this?
"Better use an arraylist OR what is even better its successor the generic list."
i.e. - Were you saying that generic lists are preferable to ArrayLists?
- Wayne
Wednesday, August 10, 2016 11:52 AM -
Better use an arraylist of what is even better its successor the generic list.
Was there a typo error in that statement?
Was it meant to read like this?
"Better use an arraylist OR what is even better its successor the generic list."
i.e. - Were you saying that generic lists are preferable to ArrayLists?
- Wayne
Notice that he's conspicuously ... quiet?
Let me translate that absence for you: "DO NOT confuse me with facts!!"
Some people succeed because they were destined to, but most people succeed because they were determined to.
Friday, August 12, 2016 6:44 PM