What happens when the constructor uses 1 argument, but the base keyword uses 2 arguments

I have this bit of code and it will demonstrate Liskov substitution, but I'm confused about what the base keyword does with two arguments. Can someone explain?

class Rectangle
{
    public Rectangle(int width, int height)
    {
        Width = width;
        Height = height;
    }
    public virtual int Height {get;set;}
    public virtual int Width {get;set;}
    public int Area
    {
        get { return Height*Width }
}

And now for a square class that inherits a base class with two arguments. I was also curious why this next Square (int) method could use the method in a base class with a different name

private class Square : Rectangle
{
    public Square(int size) : base(size, size) {} ///here is my confusion
    public override int Width
    {
        get {return base.Width}
        set { base.Width = value; base.Height = value}
    }
    public override int Height
    { /// same thing as Width }
}
+4
source share
1 answer

base(size, size) calls the parent constructor (in this case Rectangang), this constructor takes 2 arguments, so the size is specified twice.

, width, height

+5

All Articles