tags:

views:

81

answers:

1

The following code fails to compile:

class MyClass<T> :  where T : MyClass <T>{}

Is there any way to solve this? I have used the following workaround but I was wondering if there is a better way

class MyClass <T> : IMyClass where T : IMyClass {}
interface IMyClass {}
+5  A: 

You need to put a colon after the class name only if you want to derive the class from a base class or implement an interface:

class MyClass<T> where T : MyClass<T>
//              ↑
//              no ':' here
dtb