问题
Possible Duplicate:
Declare a Const Array
I need an array of const strings in the class. Something like
public class some_class_t
{
public const string[] names = new string[4]
{
"alpha", "beta", "gamma", "delta"
};
}
But this code causes an error:
A constant 'names' of reference type 'string[]' can only be initialized with null.
What should I do?
回答1:
Declare it as readonly
instead of const
:
public readonly string[] names = { "alpha", "beta", "gamma", "delta" };
来源:https://stackoverflow.com/questions/14063203/const-array-of-strings