redef array

  • Thread starter Thread starter Mex
  • Start date Start date
M

Mex

Hi

How to redfine(resize) byte array in the same scope?

lets say

byte[] pbSendBuffer= {0x0,0xA4,0x0,0xC};

//do something

now i want use same variable but

pbSendBuffer={0x0,0xa4,0x1,0xc,0x2,0xee,0xee};

Is it possible?

Best regards;
Mex
 
Mex said:
How to redfine(resize) byte array in the same scope?

lets say

byte[] pbSendBuffer= {0x0,0xA4,0x0,0xC};

//do something

now i want use same variable but

pbSendBuffer={0x0,0xa4,0x1,0xc,0x2,0xee,0xee};

Is it possible?

Not directly. The size of the arrays is immutable, so you have to
destroy and recreate the array. You can replace your last line with this
one:

pbSendBuffer = new byte[]{0x0,0xa4,0x1,0xc,0x2,0xee,0xee};
 
Mex said:
How to redfine(resize) byte array in the same scope?

lets say

byte[] pbSendBuffer= {0x0,0xA4,0x0,0xC};

//do something

now i want use same variable but

pbSendBuffer={0x0,0xa4,0x1,0xc,0x2,0xee,0xee};

Is it possible?

You need to create a new array, eg

pbSendBuffer = new byte[] {0x0,0xa4,0x1,0xc,0x2,0xee,0xee};

If you want to create a new array which has the contents of another
array to start with, look at Array.Resize<T> (if you're using C# 2).
 
ehh of course :)))

thnx!


Mex

Alberto Poblacion said:
Mex said:
How to redfine(resize) byte array in the same scope?

lets say

byte[] pbSendBuffer= {0x0,0xA4,0x0,0xC};

//do something

now i want use same variable but

pbSendBuffer={0x0,0xa4,0x1,0xc,0x2,0xee,0xee};

Is it possible?

Not directly. The size of the arrays is immutable, so you have to
destroy and recreate the array. You can replace your last line with this
one:

pbSendBuffer = new byte[]{0x0,0xa4,0x1,0xc,0x2,0xee,0xee};
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top