Inherit from generic base type

A

Arne Vajhøj

I was expecting the following code to work in C# 4.0:

public class MyGenericType<T>: T
{
//... stuff ...
}

But it doesn't.

Perhaps the syntax is different than what I'm attempting? Or is it
just that it still hasn't been implemented and maybe in C# 5.0?

http://books.google.com/books?id=kQ...rom t because it is a type parameter"&f=false

I don't think you can do that.

There is a huge practical problem. Generic classes in C#
get compiled as they are (unlike C++ templates that
get compiled when they get used). It could be very
difficult to compile something inheriting from something unknown.

Arne
 
C

CSharpner

I don't think you can do that.

There is a huge practical problem. Generic classes in C#
get compiled as they are (unlike C++ templates that
get compiled when they get used). It could be very
difficult to compile something inheriting from something unknown.

Arne

If they didn't implement it on usage, then yes, it would be difficult,
if not impossible, BUT, there's nothing preventing them from
implementing it a different way... They could generate it based on
usage. So, the story line is that they will eventually implement it,
so I was just checking to see if anyone knows if it's actually been
implemented yet. If you don't know, that's OK.
 
A

Arne Vajhøj

If they didn't implement it on usage, then yes, it would be difficult,
if not impossible, BUT, there's nothing preventing them from
implementing it a different way... They could generate it based on
usage. So, the story line is that they will eventually implement it,
so I was just checking to see if anyone knows if it's actually been
implemented yet. If you don't know, that's OK.

C#/.NET generic classes get compiled as other classes.

Arne
 
Top