bytearray - Assigning values to a public byte array in one line C# -


i working public byte array , assign values, assign arrays inside method, i.e

byte[] foo = {0x32, 0x00, 0x1e, 0x00}; 

but when define values forced do

foo[0] = 0x32; foo[1] = 0x00; foo[2] = 0x1e; foo[3] = 0x00; 

if use first example vs gives error "only assignment, call, increment, decrement, await, , new object expressions can used statement"

if helps any, array 4 bytes.

my code

public byte[] setspeed = new byte[4]; private void trackbar1_scroll(object sender, eventargs e) {     if (trackbar1.value == 0)     {         try         {             stop = true;             updatesthread.abort();             thread.sleep(350);         }         catch { }         setspeed = {0x00,0x00,0x00,0x00};         writemem(getplayer() + status_offset, setspeed);         label1.text = "normal";                   } } 

your first example fine may used in declaration. elements must implicitly convertible element type. size determined number of elements given.

byte[] foo = { 0x32, 0x00, 0x1e, 0x00 }; 

alternatively can d this

byte[] foo = new byte[4]; foo[0] = 0x32; foo[1] = 0x00; foo[2] = 0x1e; foo[3] = 0x00; 

as stated above syntax trying use can used in declaration. try this.

public byte[] setspeed; private void trackbar1_scroll(object sender, eventargs e) {     if (trackbar1.value == 0)     {         try         {             stop = true;             updatesthread.abort();             thread.sleep(350);         }         catch { }          //note create new array         setspeed = new byte[]{0x00,0x00,0x00,0x00};          writemem(getplayer() + status_offset, setspeed);         label1.text = "normal";                   } } 

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -