Why has to be size of dynamically-allocated array a static field?
- by Ondrej Slinták
I have a dummy class where I am testing arrays. I've noticed that when I want to dynamically allocate size of array at runtime, fields that indicate this size have to be static. I know I should probably use collections for this kind of code, but I'm more interested why do these fields have to be static? Is there any particular reason behind this?
class Foo
{
private static int x;
private static int y;
private int[,] bar = new int[ x, y ];
public Foo( int a, int b )
{
x = a;
y = b;
}
}