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

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

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

17条回答
  •  离开以前
    2020-12-04 06:13

    OVERKILL!

    public static class AwesomeExtensions
    {
        public static bool IsPositive(this int number)
        {
            return number > 0;
        }
    
        public static bool IsNegative(this int number)
        {
            return number < 0;
        }
    
        public static bool IsZero(this int number)
        {
            return number == 0;
        }
    
        public static bool IsAwesome(this int number)
        {
            return IsNegative(number) && IsPositive(number) && IsZero(number);
        }
    }
    

提交回复
热议问题