I would like to create the following class fragment
class Lookup<TKey,TValue,TCollection>
where TCollection : ICollection<>
{
public TCollection<TKey> _KeyCollection;
public TCollection<TValue> _ValueCollection;
}
Is this pattern generally possible in C #? In the current form, he does not like the compiler. It seems you cannot hold back the type parameter as generic. However, it seems like a reasonable thing to do. Is there a trick to achieving this?
Note . This question is specifically about generics and type restrictions. He is not looking for work around what you think I'm trying to do in my broader application.
source
share