0

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#?

2
Contributors
3
Replies
14
Views
4 Years
Discussion Span
Last Post by Ketsuekiame
2

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.

Edited by Ketsuekiame

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.