can i :
class X<T>
where T : EventArgs
{
}
class X<T>
where T:Exception
{
}
in C#?
can i :
class X<T>
where T : EventArgs
{
}
class X<T>
where T:Exception
{
}
in C#?
No, because the two clases do have the same name.
What are you trying to do?
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.
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.