Dynamic ByteArray?

  • Thread starter Thread starter Martin Greul
  • Start date Start date
M

Martin Greul

Hello!

I don't know the size of the array?
How is the correct way to make it dynamic ?

Like ReDim in Basic?

Have somebody a good example?


Thanks.


Greeting Martin





private void button1_Click(object sender, EventArgs e)
{
Endian.Test_Send();
Endian.Test_Receive();

Byte[] bytesSend = new Byte[1000];

Endian.Test_Send_ByteArrayAsReference(ref bytesSend);

}


public static void Test_Send_ByteArrayAsReference(ref Byte[] bytesSend)
{

int i = 365;
// write in big-endian order, regardless of host order
bytesSend[0] = (Byte)(i >> 24);
bytesSend[1] = (Byte)(i >> 16);
bytesSend[2] = (Byte)(i >> 8);
bytesSend[3] = (Byte)i;

}
 
Hello!

I don't know the size of the array?
How is the correct way to make it dynamic ?

Like ReDim in Basic?

Have somebody a good example?

See Array.Resize()

Not that you will actually need that for the specific examples you've been
asking about here. But if you want to "ReDim" as in VB.NET, that's
essentially the equivalent.
 
Martin said:
Hello!

I don't know the size of the array?
How is the correct way to make it dynamic ?

Like ReDim in Basic?

Better than that said:
Have somebody a good example?

List<byte> message = new List<byte>();
message.Add(1);
message.Add(2);
message.Add(3);
message.Add(4);
Thanks.


Greeting Martin





private void button1_Click(object sender, EventArgs e)
{
Endian.Test_Send();
Endian.Test_Receive();

Byte[] bytesSend = new Byte[1000];

Endian.Test_Send_ByteArrayAsReference(ref bytesSend);

}


public static void Test_Send_ByteArrayAsReference(ref Byte[] bytesSend)

There is no reason to send the byte array as a ref parameter unless you
have to replace it with another array in the method.
{

int i = 365;
// write in big-endian order, regardless of host order
bytesSend[0] = (Byte)(i >> 24);
bytesSend[1] = (Byte)(i >> 16);
bytesSend[2] = (Byte)(i >> 8);
bytesSend[3] = (Byte)i;

}
 
Back
Top