I am trying to compile following code in C#
String[] words = { "Hello", "Worlds" };
words = {"Foo", "Bar"};
and am getting compilation errors like
Error 1 Invalid expression term '{'
Error 2 ; expected
Error 3 Invalid expression term ','
On the other hand if i try
String[] words = { "Hello", "Worlds" };
words = new String[] {"Foo", "Bar"};
It compiles fine. As per MSDN
int[] a = {0, 2, 4, 6, 8};
is simply shorthand for an equivalent array creation expression:
int[] a = new int[] {0, 2, 4, 6, 8};
Now my question is that why the first code sample doesn't compile?
Thanks