Here is my code
public class MyClass
{
int LeftPoints;
int RightPoints;
public MyClass(int points)
: this (points, points)
{
if (points < 0)
throw new ArgumentOutOfRangeException("points must be positive");
}
public MyClass(int leftPoints, int rightPoints)
{
if (leftPoints < 0)
throw new ArgumentOutOfRangeException("leftPoints must be positive");
if (rightPoints < 0)
throw new ArgumentOutOfRangeException("rightPoints must be positive");
}
}
It is obvious that if I call new MyClass(-1)
it throws the message "leftPoints must be positive".
It is possible to overload the first constructor using : this (points, points)
and still get "the right" validation?