Why can't I just re-declare an array with commas?
static void Main(string[] args)
{
short[] arr = new short[6] { 1,1,1,1,1,1 };
if(1)
{
arr = {1,0,0,1,1,0}; // this line doesn't work
}
}
The initialization expression is not {1,0,0,1,1,0}
The initialization expression must be new short[6] { 1,1,1,1,1,1 }
So, essentially, the statement of your question is the answer to your question.
This syntax : short[] arr = {1, 0, 0, 1, 1, 0};
is called array initialization syntax and it works only in declaration.
why ?
As the guy here wrote, it just how Microsoft guys choose to implement for some reason.
if(1), what is this javascript?if(1)will not compile in C#, and its much different fromif(someBoolVar)See for yourself