static class SqrtPrecalculated
public const int MaxValue = 100;
private static int[] sqrtValues;
static SqrtPrecalculated()
sqrtValues = new int[MaxValue + 1];
for (int i = 1; i < sqrtValues.Length; i++)
sqrtValues[i] = (int)Math.Sqrt(i);
public static int GetSqrt(int value)
if ((value < 0) || (value > MaxValue))
throw new ArgumentOutOfRangeException(String.Format(
"The argument should be in range [0...{0}].",
return sqrtValues[value];
public static void Main()
Console.WriteLine(SqrtPrecalculated.GetSqrt(254));