Linked Questions
13 questions linked to/from Why cannot C# generics derive from one of the generic type parameters like they can in C++ templates?
32
votes
3
answers
36k
views
Inheritance on a constrained generic type parameter
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 ...
17
votes
7
answers
56k
views
generic inheritance in C#? [duplicate]
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 ...
4
votes
3
answers
9k
views
Generic class that inherits its generic type [duplicate]
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?...
1
vote
2
answers
14k
views
What is the equivalent of a template class in C# that inherits from the specified type? [duplicate]
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 ...
0
votes
1
answer
5k
views
Can you extend a generic class in C# [duplicate]
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;
}
}...
1
vote
1
answer
44
views
Generics Inheritance and conversion [duplicate]
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 ...
33
votes
4
answers
22k
views
In C# 4.0, is it possible to derive a class from a generic type parameter?
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(...
18
votes
8
answers
2k
views
What are the good reasons to wish that .NET generics could inherit one of the generic parameter types?
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
Work around for deriving from a generic type parameter
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 ...
10
votes
1
answer
316
views
Redundant generic constraint?
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 '...
1
vote
4
answers
172
views
Controller returns value that not match with view?
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, ...
1
vote
2
answers
94
views
Inheriting a generic in c#
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 ...
0
votes
0
answers
57
views
Using generic parameter as base class [duplicate]
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 ...