In C#, what exactly is the reason for this syntax to work for an array initialization :
string[] strArray = {"foo1", "foo2"}; //works
but not for an assignment :
strArray = {"foo1", "foo2"}; //does not work, throws "; expected" exception
In C#, what exactly is the reason for this syntax to work for an array initialization :
string[] strArray = {"foo1", "foo2"}; //works
but not for an assignment :
strArray = {"foo1", "foo2"}; //does not work, throws "; expected" exception
You need to specifies the size of an array. When you mention items of an array exactly when you define it, the size of array will be defined automatically. But when you want to give it values later, you need to specify size of the array when you're creating it.
string[] strArray = new string[number]; //number is size of your array.
So in this way you can valuate this array whenever later you want.
strArray = {"foo1","foo2"};