int[] outSize = new int[]{bytes, packets};
new byte[] {0, 0, 0, 0}
What does the first line of code mean? What is it doing to size array? How is the second line of code initializing that byte array (if it is at all)?
int[] outSize = new int[]{bytes, packets};
new byte[] {0, 0, 0, 0}
What does the first line of code mean? What is it doing to size array? How is the second line of code initializing that byte array (if it is at all)?
We can initialized an array at the time of declaration using the given syntex
int[] outSize = new int[]{5, 9}; //create a Integer array of 2 element named outSize
OR
int bytes = 5, packets =9;
int[] outSize = new int[]{bytes, packets}; //create a Integer array of 2 element named outSize.
there is no difference using both the above statement.
First line
int[] outSize = new int{ bytes, packets };
This creates an integer (primitive) array with two integer elements, namely bytes
and packets
.
Second line
new byte[] { 0, 0, 0, 0 }
By itself, this will give you an error (not compile) since it isn't a statement (there's no assignment to a variable anywhere).
If you write
byte[] bytes = new byte[] { 0, 0, 0, 0 };
you are declaring a byte array called bytes
with four elements.
Use of {} for array initialization
Refer to chapter 10 (arrays) of the documentation, particularly sections 10.1 and 10.2.
Also worth reading, the primitive data types.
From the above:
int
is a 32-bit signed two's complement integer (min value in base 10 is -2^31
and max is 2^31 - 1
).
byte
is an 8-bit signed two's complement integer (min value in base 10 is -2^7
and max is -2^7 - 1
).
What it's doing
The first line uses 64 bits to store two integers.
The second line uses 32 bits to store four bytes.