Is there a way to use a generic class / method with 2 types that won't be the same?

I can create a generic class and use a "where" statement like:

public class TestClass<T> where T: IDisposable
{
    .... 
}

      

To make sure that type "T" implements the "IDisposable" interface.

Is there a way to create a generic class with 2 types that constrain the types to be different from each other, for example:

public class TestClass<T,K> where T!=K
{
    .... 
}

      

thank

+3
generics c # .net


source to share


No one has answered this question yet

See similar questions:

8
Type exclusion in general constraints (maybe?)

or similar:

1565
Correct use of the IDisposable interface
1476
Hidden features of C #?
1270
Why not inherit from List <T>?
1266
How do I update the GUI from another thread?
1106
Create a generic method limiting T to Enum
636
How do I get the type T from a member of a generic class or method?
547
Create an instance of a generic type in Java?
417
How do I make a method return type generic?
393
General list of anonymous class
315
Is there a limitation that restricts my generic method to numeric types?



All Articles
Loading...
X
Show
Funny
Dev
Pics