Can't use String[] as const

  • Thread starter Thread starter John Bailo
  • Start date Start date
J

John Bailo

Why can't I do this:

private const String[] words = new String[] {
"house",
"car"};
 
John Bailo said:
Why can't I do this:
private const String[] words = new String[]
{ "house", "car"};

I'm not quite sure, but it will work if you use readonly instead of
const.

P.
 
Paul E Collins said:
John Bailo said:
Why can't I do this:
private const String[] words = new String[]
{ "house", "car"};

I'm not quite sure, but it will work if you use readonly instead of
const.

That depends on what you mean by "work". Making it readonly won't stop
you from doing:

words[0] = "foo";
 
Back
Top