F
Fabrizio
Hi
I cannot figure why it isn't possible to cast a struct array to an object
array.
I written a structure like this:
public struct Test {
private int TestA;
private int TestB;
public int A {
get {return this.TestA;}
}
public int B {
get {return this.TestB;}
}
public Test(int a, int b) {
this.TestA=a;
this.TestB=b;
}
}
I have an array of Test struct values (Test[]):
Test[] = new my_struct[2];
my_struct[0] = new Test(1,2);
my_struct[1] = new Test(2,3);
but if I try to cast the structure array to the object:
object[] dest = (object[])my_struct;
the compiler tells me that it isn't possible to cast Test[] to object[],
although it gives me no error if I cast a single Test struct value to
object:
object o = (object)my_struct[0];
Moreover, if i change the struct declaration to a class declaration, no
error occurs for a class array to an object array!
Should I perform some casting operator overload in Test?
TIA
Fabrizio
I cannot figure why it isn't possible to cast a struct array to an object
array.
I written a structure like this:
public struct Test {
private int TestA;
private int TestB;
public int A {
get {return this.TestA;}
}
public int B {
get {return this.TestB;}
}
public Test(int a, int b) {
this.TestA=a;
this.TestB=b;
}
}
I have an array of Test struct values (Test[]):
Test[] = new my_struct[2];
my_struct[0] = new Test(1,2);
my_struct[1] = new Test(2,3);
but if I try to cast the structure array to the object:
object[] dest = (object[])my_struct;
the compiler tells me that it isn't possible to cast Test[] to object[],
although it gives me no error if I cast a single Test struct value to
object:
object o = (object)my_struct[0];
Moreover, if i change the struct declaration to a class declaration, no
error occurs for a class array to an object array!
Should I perform some casting operator overload in Test?
TIA
Fabrizio