# In C#, how do I determine whether an integer is positive or negative?

## Problem

In C#, how do I determine whether an integer is positive or negative?

## Solution #1

``````bool positive = number > 0;
bool negative = number < 0;
``````

## Solution #2

Of course, no one has supplied the correct response.

``````num != 0   // num is positive *or* negative!
``````

## Solution #3

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);
}
}
``````

## Solution #4

One option is to use the Math.Sign technique. For negative numbers, it will return -1, for positive numbers, 1 and for zero values, it will return 0. (i.e. zero has no sign). If a double or single precision variable equals NaN, an exception (ArithmeticException) will be thrown.

``````num < 0 // number is negative