tags:

views:

61

answers:

1

I have a generic type Foo which has a internal generic class Boo. Boo class a property Value of type K. In a method inside Foo i want to do a boo.Value >= value Note that second operand value is of type T. while compiling i am getting following error:

Operator '>=' cannot be applied to operands of type 'T' and 'T'

Can anyone please tell me whats the problem here?

+4  A: 

Hi!

Restrict the type argument to IComparable , then you can implement the operations with the CompareTo method. Of course, you won't be able to use your generic class with every type, but I think every built-in type which can be compared using such operators like >, <=, ... implements this interface.

Best Regards,
Oliver Hanappi

Oliver Hanappi