How do I check if a number is positive or negative in C#?

前端 未结 17 1469
轻奢々
轻奢々 2020-12-04 05:55

How do I check if a number is positive or negative in C#?

17条回答
  •  旧巷少年郎
    2020-12-04 06:35

    public static bool IsNegative(T value)
       where T : struct, IComparable
    {
        return value.CompareTo(default(T)) < 0;
    }
    

提交回复
热议问题