Can't operator == be applied to generic types in C#?

前端 未结 12 850
囚心锁ツ
囚心锁ツ 2020-11-22 02:21

According to the documentation of the == operator in MSDN,

For predefined value types, the equality operator (==) returns true if th

12条回答
  •  暖寄归人
    2020-11-22 02:27

    I wrote the following function looking at the latest msdn. It can easily compare two objects x and y:

    static bool IsLessThan(T x, T y) 
    {
        return ((IComparable)(x)).CompareTo(y) <= 0;
    }
    

提交回复
热议问题