I’ve got a situation where I have several classes that have somethings in common and somethings unique. I’d like to create a class that is more strongly typed than object[] but could hold any of these other classes.
If I have for example:
class MyType1
{
string common1;
string common2;
string type1unique1;
string type1unique2;
//Constructors Here
}
class MyType2
{
string common1;
string common2;
string type2unique1;
string type2unique2;
//Constructors Here
}
I’d like to create a class something like:
class MyObject
{
string common1;
string common2;
//Code Here
}
So that I create something like:
Dictionary<int, MyObject>
That would hold either MyType1 or MyType2 but not string or int or anything else a dictionary would hold. The MyObjects that are stored there would need to be able to be recast to MyType1 or MyType2 later to access the unique attributes underneath.
Also it would be really great if I could access MyObject.common1 or MyObject.common2 without recasting it.
1 Answer