开发者

c# Template specialization [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. 开发者_JS百科 Closed 10 years ago.

can i :

    class X<T>
        where T : EventArgs
    {

    }

    class X<T>
        where T:Exception
    {

    }

in C#?


You can't use the same class name for the generic constraints.

You can use base classes as constraints, but the constraint then means that you can only use derived classes - in your examples, only classes that derive from EventArgs in the first example and classes that derive from Excpetion in the second.

See the documentation for constraints on type parameters.


No, because the two clases do have the same name.

What are you trying to do?


If you mean 2 classes with the same name in the same namespace with different generic type parameters - then NO, you can't!

You can only have one class in the where clause. You could use the

System.Runtime.InteropServices._Exception

interface to accept Exceptions (that would be an ugly hack, though).

If you put them in separate namespaces, you can.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜