아니, ArgumentOutOfRangeException
생성자의 인수는 항상해야 하나 이름. 둘 중 하나를 선택할 수 있습니다. 보통 이전의 매개 변수가 올바른 것으로 가정하므로 나중에 매개 변수와 관련하여 올바르지 않습니다. 메시지에서 더 많은 정보를 제공 할 수 있습니다.
internal static void CheckArgumentRange(string paramName,
int value, int minInclusive, int maxInclusive)
{
if (value < minInclusive || value > maxInclusive)
{
throw new ArgumentOutOfRangeException(paramName, value,
"Value should be in range [" + minInclusive + "-" + maxInclusive + "]");
}
}
당신이 위를 단순화 수있는 방법 : Noda Time를 들어
if (min < 1 || min > 5)
{
throw new ArgumentOutOfRangeException("min", min, "min must be between 1 and 5 inclusive");
}
if (max < 1 || max > 5)
{
throw new ArgumentOutOfRangeException("max", max, "max must be between 1 and 5 inclusive");
}
if (max < min)
{
throw new ArgumentOutOfRangeException("max", max, "max must not not be less than min");
}
나는 등이 헬퍼 방법을 가지고, 그래서 - 당신이 실제 값을 주면 정말 또한 편리한 입니다 :
Preconditions.CheckArgumentRange("min", min, 1, 5);
Preconditions.CheckArgumentRange("max", max, 1, 5);
if (max < min)
{
throw new ArgumentOutOfRangeException("max", max, "max must not not be less than min");
}