Is it possible to write something similar to the following?
public const string[] Titles = { "German", "Spanish", "Corrects", "Wrongs" };
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, but you need to declare it
readonlyinstead ofconst:The reason is that
constcan only be applied to a field whose value is known at compile-time. The array initializer you’ve shown is not a constant expression in C#, so it produces a compiler error.Declaring it
readonlysolves that problem because the value is not initialized until run-time (although it’s guaranteed to have initialized before the first time that the array is used).Depending on what it is that you ultimately want to achieve, you might also consider declaring an enum: