public static void Cap( ref int val, int min, int max ) { if ( val < min ) val = min; else if ( val > max ) val = max; }