Aaron Thomas Aaron Thomas - 1 year ago 133
C# Question

Multiple comparison operators

What is the standard way in C# to check if a number is within a range of numbers?

Typically, I would do some variation of this with int


return (i >= start && i <= end);

Is there no syntax for something like this:

// does not work
return (start <= i <= end);

Answer Source

The most close to what you expect is

return start <= i && i <= end;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download