Why cant i declare this!
-
public const byte[] FOO = {0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF,0x0074, 0x0001, 0x0003,0x0075, 0x0003, 0x0000}; I get a complie error Array initializers can only be used in a variable or field initializer. Try using a new expression instead. And yes i have tried using new, i cant get that either, someone help me plz ?
-
public const byte[] FOO = {0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF,0x0074, 0x0001, 0x0003,0x0075, 0x0003, 0x0000}; I get a complie error Array initializers can only be used in a variable or field initializer. Try using a new expression instead. And yes i have tried using new, i cant get that either, someone help me plz ?
hmmm, seems like a stupid problem; the compiler should be able to take care of that or so I would think. This does the trick though, hope it helps.
public static readonly byte [] FOO = new byte[] {
0x00FF, 0x00FF, 0x00FF,
0x00FF, 0x00FF,0x0074,
0x0001, 0x0003,0x0075,
0x0003, 0x0000
};James Sonork ID: 100.11138 - Hasaki "My words but a whisper -- your deafness a SHOUT. I may make you feel but I can't make you think." - Thick as a Brick, Jethro Tull 1972
-
hmmm, seems like a stupid problem; the compiler should be able to take care of that or so I would think. This does the trick though, hope it helps.
public static readonly byte [] FOO = new byte[] {
0x00FF, 0x00FF, 0x00FF,
0x00FF, 0x00FF,0x0074,
0x0001, 0x0003,0x0075,
0x0003, 0x0000
};James Sonork ID: 100.11138 - Hasaki "My words but a whisper -- your deafness a SHOUT. I may make you feel but I can't make you think." - Thick as a Brick, Jethro Tull 1972
You can only use 'const' on simple values that can be computed at compile time. For example, assigning a fixed value. Your code wants to do something more complex which involves creating a new object. Just because we can see it is fixed does not mean the compiler can. Therefore you need to use 'readonly' instead of 'const' to get the same effect. Phil Wright uk_phil_wright@hotmail.com