In java this is how a DerivedClass can implement it's BaseClass's constructor.

public DerivedClass extends BaseClass
{
    //some properties
    public DerivedClass(param)
    {
        super(param);
    }
}

I have learnt C-Sharp's base() does the similar thing, but when I replace super(param) with base(param), it does not gives what I'm expecting. How can I implement this code snippet in C#?

Recommended Answers

All 3 Replies

The syntax for calling base is public constructor() : base().

It will call the matching base class constructor based on the parameters given to it.

So;
public MyClass() : base() {} will match it up to the constructor that takes no parameters.
public MyClass(String param) : base(param) will match it to the constructor that takes a single string parameter.

The base constructors must be either public or protected.

thanks @Ketsuekiame, that solved my problem. :)

Please mark as solved if so :)

Easier to filter threads that way.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.