I'm new to C# and was reading the article about the virtual
keyword at the MSDN. In their example code, they create the following class:
public class Dimensions
{
protected double x, y;
public Dimensions()
{
}
public Dimensions(double x, double y)
{
this.x = x;
this.y = y;
}
public virtual double Area()
{
return x * y;
}
}
Why did they add the first constructor (the one that does not require any parameters)? I get that the two double values x
and y
default to 0 so adding this constructor does not hurt. But I've seen this now numerous times and am therefore wondering if there is any special reason behind always adding such a constructor? Should I always do this?