Declaring a const double[] in C#?

c#, constants, readonly, static

Solution

From MSDN (http://msdn.microsoft.com/en-us/library/ms228606.aspx)

A constant-expression is an expression that can be fully evaluated at compile-time. Because the only way to create a non-null value of a reference-type [an array] is to apply the new operator, and because the new operator is not permitted in a constant-expression, the only possible value for constants of reference-types other than string is null.

Problem

I have several constants that I use, and my plan was to put them in a const array of doubles, however the compiler won't let me. I have tried declaring it this way: ``` const double[] arr = {1, 2, 3, 4, 5, 6, 73, 8, 9 }; ``` Then I settled on declaring it as static readonly: ``` static readonly double[] arr = { 1, 2, 3, 4, 5, 6, 7, 8, 9}; ``` However the question remains. Why won't compiler let me declare an array of const values? Or will it, and I just don't know how?

Original source

Related problems