J John Bailo Dec 6, 2004 #1 Why can't I do this: private const String[] words = new String[] { "house", "car"};
C C# Learner Dec 6, 2004 #2 John Bailo said: Why can't I do this: private const String[] words = new String[] { "house", "car"}; Click to expand... Because new String[] { "house, "car" } cannot be computed at compile time. See <http://www.jaggersoft.com/csharp_standard/8.7.1.htm> for details. The usual practise here would be to use: static readonly instead. See also: http://msdn.microsoft.com/library/d...n-us/csspec/html/vclrfcsharpspec_10_4_2_1.asp - or - http://tinyurl.com/62p58
John Bailo said: Why can't I do this: private const String[] words = new String[] { "house", "car"}; Click to expand... Because new String[] { "house, "car" } cannot be computed at compile time. See <http://www.jaggersoft.com/csharp_standard/8.7.1.htm> for details. The usual practise here would be to use: static readonly instead. See also: http://msdn.microsoft.com/library/d...n-us/csspec/html/vclrfcsharpspec_10_4_2_1.asp - or - http://tinyurl.com/62p58
P Paul E Collins Dec 6, 2004 #3 John Bailo said: Why can't I do this: private const String[] words = new String[] { "house", "car"}; Click to expand... I'm not quite sure, but it will work if you use readonly instead of const. P.
John Bailo said: Why can't I do this: private const String[] words = new String[] { "house", "car"}; Click to expand... I'm not quite sure, but it will work if you use readonly instead of const. P.
J Jon Skeet [C# MVP] Dec 7, 2004 #4 Paul E Collins said: John Bailo said: Why can't I do this: private const String[] words = new String[] { "house", "car"}; Click to expand... I'm not quite sure, but it will work if you use readonly instead of const. Click to expand... That depends on what you mean by "work". Making it readonly won't stop you from doing: words[0] = "foo";
Paul E Collins said: John Bailo said: Why can't I do this: private const String[] words = new String[] { "house", "car"}; Click to expand... I'm not quite sure, but it will work if you use readonly instead of const. Click to expand... That depends on what you mean by "work". Making it readonly won't stop you from doing: words[0] = "foo";