C# constructors overloading

Aleksandr Vishnyakov picture Aleksandr Vishnyakov · Apr 5, 2011 · Viewed 105.6k times · Source

How I can use constructors in C# like this:

public Point2D(double x, double y)
{
    // ... Contracts ...

    X = x;
    Y = y;
}

public Point2D(Point2D point)
{
    if (point == null)
        ArgumentNullException("point");
    Contract.EndContractsBlock();

    this(point.X, point.Y);
}

I need it to not copy code from another constructor...

Answer

Mark Cidade picture Mark Cidade · Apr 5, 2011
public Point2D(Point2D point) : this(point.X, point.Y) { }