Aaron Thomas Aaron Thomas - 2 months ago 24
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

i
:

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


Is there no syntax for something like this:

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

Answer

The most close to what you expect is

return start <= i && i <= end;