comparing variables

  • Thread starter Thread starter Mike P
  • Start date Start date
M

Mike P

I have 3 variables, 1 is the beginning of a integer range, 1 is the end
of an integer range, and the other is an integer I want to check whether
or not it is between the range defined by the other 2. How do I do this
check in C#?

Any help would be much appreciated.


Cheers,

Mike
 
Mike P said:
I have 3 variables, 1 is the beginning of a integer range, 1 is the end
of an integer range, and the other is an integer I want to check whether
or not it is between the range defined by the other 2. How do I do this
check in C#?

Assuming the one you wish to test is "value", the lowest end of the
range is "bottom" and the highest end of the range is "top", you'd use
something like:

boolean isInRange = (value >= bottom && value <= top);
 
Mike P said:
I have 3 variables, 1 is the beginning of a integer
range, 1 is the end of an integer range, and the
other is an integer I want to check whether or
not it is between the range defined by the other 2.
How do I do this check in C#?

Is this what you mean?

if (value >= min && value <= max)
{
// value is between min and max
}

P.
 
Back
Top