Bohn
Bohn

Reputation: 26929

Why I cannot use BASE in my inheritance

Exactly this code: compile error says use of base is not valid in this context.

public class UCMComboBoxCellType : FarPoint.Win.Spread.CellType.ComboBoxCellType
{
    public UCMComboBoxCellType()
    {
        base();
        this.ListWidth = 0;
    }
}

but why? I cannot figure out.

Upvotes: 0

Views: 129

Answers (3)

Joe
Joe

Reputation: 42666

Because you don't.

If you needed to call a parameterized baseclass constructor, you'd do so like so:

public MyClass(string msg)
    : base(msg)
{
...
}

but in a parameterless case, there is no need -- it is implied that the derived constructor will call the base class constructor first.

Upvotes: 2

alun
alun

Reputation: 3441

Try this:

public class UCMComboBoxCellType : FarPoint.Win.Spread.CellType.ComboBoxCellType
{
    public UCMComboBoxCellType() : base()
    {
        this.ListWidth = 0;
    }
}

Upvotes: 1

Paul Phillips
Paul Phillips

Reputation: 6259

In C# you chain constructors like this:

public UCMComboBoxCellType() : base()
{        
    this.ListWidth = 0;
}

What you tried is the Java way.

Upvotes: 8

Related Questions