Base Class Doesn't Contain Parameterless Constructor?

In class A2, you need to make sure that all your constructors call the base class constructor with parameters.

Otherwise, the compiler will assume you want to use the parameterless base class constructor to construct the A object on which your A2 object is based.

Example:

class A
{
    public A(int x, int y)
    {
        // do something
    }
}

class A2 : A
{
    public A2() : base(1, 5)
    {
        // do something
    }

    public A2(int x, int y) : base(x, y)
    {
        // do something
    }

    // This would not compile:
    public A2(int x, int y)
    {
        // the compiler will look for a constructor A(), which doesn't exist
    }
}

Example:

class A2 : A
{
   A2() : base(0)
   {
   }
}

class A
{
    A(int something)
    {
        ...
    }
}

If your base class doesn't have a parameterless constructor, you need to call one from your derived class using base keyword:

class A
{
    public A(Foo bar)
    {
    }
}

class A2 : A
{
    public A2()
        : base(new Foo())
    {
    }
}

It has to call some constructor. The default is a call to base().

You can also use static methods, literals, and any parameters to the current constructor in calls to base().

  public static class MyStaticClass
    {
        public static int DoIntWork(string i)
        {
            //for example only
            return 0;
        }
    }

    public class A
    {
        public A(int i)
        {
        }
    }

    public class B : A
    {
        public B(string x) : base(MyStaticClass.DoIntWork(x))
        {
        }
    }