dpanattoni
IS-IT--Management
I have a need to store a struct into a class variable that has no knowledge of the struct definition. For example, the class has:
public class Storage {
public object Data;
.
.
.
}
Within the program that is including the Storage class, there is a struct defined as:
public struct DataStruct {
public string Name;
public string Address;
.
.
.
}
From the program, it appears that I can store DataStruct into the class's Data object. (At least I'm not getting any errors so I assume it's working). But when I try to bring the class's Data object back into the DataStruct, I am getting an error at runtime.
Is this possible with C#? or is there a better way to define the class's data object?
In C, I define the data object as a void * and then I can cast the pointer as any type of struct that I need to from within the program. The program determines what type of struct is stored within the class's data object.
Thanks in advance.
DP
public class Storage {
public object Data;
.
.
.
}
Within the program that is including the Storage class, there is a struct defined as:
public struct DataStruct {
public string Name;
public string Address;
.
.
.
}
From the program, it appears that I can store DataStruct into the class's Data object. (At least I'm not getting any errors so I assume it's working). But when I try to bring the class's Data object back into the DataStruct, I am getting an error at runtime.
Is this possible with C#? or is there a better way to define the class's data object?
In C, I define the data object as a void * and then I can cast the pointer as any type of struct that I need to from within the program. The program determines what type of struct is stored within the class's data object.
Thanks in advance.
DP