I was wondering what's the reason behind the syntax? I mean it's like this:
int[ , ] arrayName = new int[10,10];
Wouldn't it be simpler if we had something like:
int[10,10] arrayName ;
What caused the software architect to make such a decision?
It's because you can declare the variable in one scope, and initialize it in another (normally in a constructor).
Something like this:
public class Foo
{
private int[ , ] Bar; // Bar will be null until initialized
public Foo(int a, int b)
{
Bar = new int[a, b];
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With