How to initialize "public const short[] test"?

  • Thread starter Thread starter babylon
  • Start date Start date
B

babylon

I can't do
public const short[] test = new short[]{1000,2000,3000};

any suggestions?

thx
 
oic ...
then it should be
public static readonly short[] test = new short[] {1000, 2000, 3000};
as a const member is static

thank you!


any suggestions?

public readonly short[] test = new short[] {1000, 2000, 3000};

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)
 
If you have a really complicated init that you need to run for a const
member, you can write a static method which returns the result.

private static short[] InitTest() {
short[] res = null;
// do lots of complicated stuff here
return res;
}
public const short[] test = InitTest();

--Don
 
Don Dumitru said:
If you have a really complicated init that you need to run for a const
member, you can write a static method which returns the result.

private static short[] InitTest() {
short[] res = null;
// do lots of complicated stuff here
return res;
}
public const short[] test = InitTest();

No you can't, because "const" can't apply to arrays. Even if it could,
it *really* couldn't apply to something like the above, as "const"s are
meant to be *compile-time* constants.
 
Back
Top