I have tried to create an array of classes, first of regular classes, then of static classes, in both cases, it hasn't worked. It hasn't compiled.
class Program
{
static class A : Bunch1 { }
static class B : Bunch1 { }
class AA : Bunch2 { }
class BB : Bunch2 { }
class Bunch1 { }
class Bunch2 { }
static void Main(string[] args)
{
Bunch1[] bunch1s = new Bunch1[] {
A,B
};
Bunch2[] bunch2s = new Bunch2[] {
AA,BB
};
}
}
The compilation error has been that AA "is a 'type' but is used like a 'variable'" (same error message for any class - A or B or AA or BB)
I can see that (at least for non static classes), I can do
Bunch2[] bunch2s = new Bunch2[] {
new AA(),new BB()
};
But I don't want instances of those classes.
I don't want an array of objects.
Added
A practical scenario of why.
I have a bunch of classes each with a static field (public static char c), and i'd like to set that field.
class A { public static char c; }
class B { public static char c; }
....
I could say
A.c='x';
B.c='p';
C.c='w';
D.c='V';
But i'd rather say
char[] mychars= new char[] {'x','p','w','V'};
// create a bunchofclasses array or list consisting of classes A,B,C,D (how, I don't know).
for(int i=0; i<5;i++)
bunchofclasses[i].c= mychars[i];