Linked Questions

32 votes
3 answers
36k views

I know it isn't possible to inherit from a generic type parameter, but it would be handy when implementing a common proxy for derivatives of an abstract type :-) Does anyone know why this isn't ...
VirtualStaticVoid's user avatar
17 votes
7 answers
56k views

Possible Duplicate: Why cannot C# generics derive from one of the generic type parameters like they can in C++ templates? I can do public class MyGenericClass : DL //but i cannot do public class ...
user avatar
4 votes
3 answers
9k views

Possible Duplicates: Why cannot C# generics derive from one of the generic type parameters like they can in C++ templates? In C# 4.0, is it possible to derive a class from a generic type parameter?...
jack-london's user avatar
  • 1,619
1 vote
2 answers
14k views

Possible Duplicate: Why cannot C# generics derive from one of the generic type parameters like they can in C++ templates? Generic class that inherits its generic type I would like to be able to ...
Dollarslice's user avatar
  • 10.4k
0 votes
1 answer
5k views

Let's say I have this class public Holder<T> : IHolder { private mystring; private myobj; public Holder(T obj, string str) { mystring = str; myobj = obj; } }...
Anders Miltner's user avatar
1 vote
1 answer
44 views

I have the following classes: class Item { } class MeetingItem : Item { } class ItemGroup<T> { } now, this works without an issue: Item something; something = new MeetingItem(); this however ...
Rob's user avatar
  • 2,130
33 votes
4 answers
22k views

I've been trying this, but I can't seem to figure this out. I want to do this... public abstract class SingletonType<TSingleton, TBaseClass> : TBaseClass where TSingleton : TBaseClass, new(...
Mark A. Donohoe's user avatar
18 votes
8 answers
2k views

This post is in continuation of this one. I am trying to understand if I am the only one who misses and needs the ability of a .NET generic type to inherit one of its generic parameter types. The ...
2 votes
1 answer
2k views

I realize it is not possible to derive from a generic type parameter, and I understand all the complications that arise if it is allowed. Generics FAQ Why it can't be done So my question is, how do I ...
Steve's user avatar
  • 7,897
10 votes
1 answer
316 views

Consider the following generic method: public T2 Frob<T1, T2>(T1 item) where T1 : class, T2 => item as T2; The compiler will refuse to compile this code; The type parameter '...
InBetween's user avatar
  • 32.9k
1 vote
4 answers
172 views

I have two classes, the first one is base class and second one is inherited from first. public class hgm { } public class Laboratory : hgm { } I used EF Code First to generate the database. Also, ...
user1331586's user avatar
1 vote
2 answers
94 views

I've inherited a large codebase and I'm trying to implement some new functionality into the framework. Basically, in order to do it the "right" way, I would have to modify the entire structure of the ...
audiFanatic's user avatar
  • 2,534
0 votes
0 answers
57 views

Can I write something like this in C# class A<TBase> : TBase {} Here's what I'm trying to do roughly: public class Comparable<T, TBase> : TBase, IComparable<T> { public abstract ...
Clinton's user avatar
  • 23.2k