MathHelper.Clamp Method

Restricts a value to be within a specified range.

Syntax

'Declaration
Public Shared Function Clamp ( _
         value As Single, _
         min As Single, _
         max As Single _
) As Single 
public static float Clamp (
         float value,
         float min,
         float max
)
public:
static float Clamp(
         float value,
         float min,
         float max
)

Parameters

  • value
    Type: Single
    The value to clamp.
  • min
    Type: Single
    The minimum value. If value is less than min, min will be returned.
  • max
    Type: Single
    The maximum value. If value is greater than max, max will be returned.

Return Value

Type: Single
The clamped value.

  • If value > max, max will be returned.
  • If value < min, min will be returned.
  • If minvaluemax, value will be returned.

Requirements

Namespace: Microsoft.Xna.Framework

Assembly: Microsoft.Xna.Framework (in microsoft.xna.framework.dll)

See Also

Reference

MathHelper Class
MathHelper Members
Microsoft.Xna.Framework Namespace

Platforms

Windows Phone