Skip to main content

A C# method that clamps an integer value to a set minimum and maximize sizes.

using System;

namespace Utilities
{
    public static class MathHelper
    {
        public static int Clamp(int value, int min, int max)
            => Math.Min(Math.Max(value, min), max);
    }
}