Determine if an int is within range
There's a method in XNA called MathHelper.Clamp that does what you need. I understand if you don't want to import XNA libraries for this one function, though. You can do this with extension methods. Here's an implementation that uses generics (so you can apply it to various types) so you can use it for ints, longs, anything that implements IComparable

static class Extensions
{
    public static T Clamp&lt;T&gt; (this T self, T min, T max) where T: IComparable
    {
        if (self.CompareTo( min) &lt;0)
            return min;
        return self.CompareTo(max) &gt; 0 ? max : self;
    }
}