comparing variables

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mike P

    #1

    comparing variables

    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




    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
  • Jon Skeet

    #2
    Re: comparing variables

    Mike P <mrp@telcoelect ronics.co.uk> wrote:[color=blue]
    > 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#?[/color]

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

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    • Paul E Collins

      #3
      Re: comparing variables

      "Mike P" <mrp@telcoelect ronics.co.uk> wrote:
      [color=blue]
      > 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#?[/color]

      Is this what you mean?

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

      P.

      --



      Comment

      Working...