can't invoke the constructor of the base of an inherited class (convert vb code to C#)

  • Thread starter Thread starter Chris LaJoie
  • Start date Start date
C

Chris LaJoie

I wrote a class in VB that inherits from a MenuItem, but I'm having
difficulty converting it to C#.
this VB is the code that must be converted:

Public Sub New()
MyBase.New()
Me.OwnerDraw = True
End Sub

That vb code works perfectly fine, and does what it's supposed to (invoke
the constructor of the base class)
here's the code I came up with for C#:

public MenuEx() {
base = new MenuItem();
this.OwnerDraw = true;
}

this code does not compile. The error is "use of keyword 'base' is not
valid in this context".
Anyone have any suggestions?

Chris LaJoie
 
Chris LaJoie said:
I wrote a class in VB that inherits from a MenuItem, but I'm having
difficulty converting it to C#.
this VB is the code that must be converted:

Public Sub New()
MyBase.New()
Me.OwnerDraw = True
End Sub

That vb code works perfectly fine, and does what it's supposed to (invoke
the constructor of the base class)
here's the code I came up with for C#:

public MenuEx() {
base = new MenuItem();
this.OwnerDraw = true;
}

this code does not compile. The error is "use of keyword 'base' is not
valid in this context".
Anyone have any suggestions?

You almost had it...

public MenuEx() : base()
{
this.OwnerDraw = true;
}

-c
 
Back
Top