S
Steven Cummings
Hello,
I've scoured this usenet group and didn't find anything specific to my
problem, so hopefully this won't be a repeated question. I'm all but
certain it's not.
I would like to *declare* (not just instantiate at runtime) a generic
collection whose element-type is a generic class too. But I don't want
to declare what the element-type's generic parameters are.
My best example is using the common "Pair" example. Suppose you have
the following:
public struct Pair<TFirst,TSecond>
{
public TFirst FirstValue;
public TSecond SecondValue;
}
Granted in my implementation I'm declaring a class, and I understand
struct is a value-type, so I don't know if this has any effect on my
problem, but onward...
I want to declare a collection of type ICollection<Pair> such that I
can put Pair<string,int> or Pair<uint,int> in it. I need type Pair to
be generic, but I need my collection to not care about that just yet.
The quick and dirty solution would be to not use generics for the
collection and always cast both ways, but I was wondering if anybody
could think of a better solution?
Thanks.
I've scoured this usenet group and didn't find anything specific to my
problem, so hopefully this won't be a repeated question. I'm all but
certain it's not.
I would like to *declare* (not just instantiate at runtime) a generic
collection whose element-type is a generic class too. But I don't want
to declare what the element-type's generic parameters are.
My best example is using the common "Pair" example. Suppose you have
the following:
public struct Pair<TFirst,TSecond>
{
public TFirst FirstValue;
public TSecond SecondValue;
}
Granted in my implementation I'm declaring a class, and I understand
struct is a value-type, so I don't know if this has any effect on my
problem, but onward...
I want to declare a collection of type ICollection<Pair> such that I
can put Pair<string,int> or Pair<uint,int> in it. I need type Pair to
be generic, but I need my collection to not care about that just yet.
The quick and dirty solution would be to not use generics for the
collection and always cast both ways, but I was wondering if anybody
could think of a better solution?
Thanks.