By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,641 Members | 1,446 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,641 IT Pros & Developers. It's quick & easy.

Can a base class implement a method on an interface for me?

P: n/a
I rarely have the pleasure of working in VB.NET so forgive my
ignorance, but what I'm trying to do is very easy in C# and I'm
wondering whether a similar thing is possible in VB.NET.

I have a class MySuperForm

Public Class MySuperForm
Inherits Form '' Yup, System.Windows.Forms.Form
Implements IMySuperForm
End Class

Public Interface IMySuperForm
Sub Show()
End Interface

In c# that would compile, but in VB.NET I need to declare which method
implements Show() but I can't because the method doesn't belong to me.
It belongs to Form.

The only workaround I have found is to shadow the Sub

Public Class MySuperForm
Inherits Form '' Yup, System.Windows.Forms.Form
Implements IMySuperForm
Public Shadows Sub Show() Implements IMySuperForm.Show
MyBase.Show()
End Sub
End Class

Is this the only way to achieve this?

Nov 16 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a

MrAnon wrote:
I rarely have the pleasure of working in VB.NET so forgive my
ignorance, but what I'm trying to do is very easy in C# and I'm
wondering whether a similar thing is possible in VB.NET.

I have a class MySuperForm

Public Class MySuperForm
Inherits Form '' Yup, System.Windows.Forms.Form
Implements IMySuperForm
End Class

Public Interface IMySuperForm
Sub Show()
End Interface

In c# that would compile, but in VB.NET I need to declare which method
implements Show() but I can't because the method doesn't belong to me.
It belongs to Form.

The only workaround I have found is to shadow the Sub

Public Class MySuperForm
Inherits Form '' Yup, System.Windows.Forms.Form
Implements IMySuperForm
Public Shadows Sub Show() Implements IMySuperForm.Show
MyBase.Show()
End Sub
End Class

Is this the only way to achieve this?
I think so... does shadowing the sub cause any serious problems?

Nov 16 '06 #2

P: n/a
"MrAnon" <jo********@gmail.comwrote in news:1163676877.010944.75070
@m73g2000cwd.googlegroups.com:
I rarely have the pleasure of working in VB.NET so forgive my
ignorance, but what I'm trying to do is very easy in C# and I'm
wondering whether a similar thing is possible in VB.NET.
Declare the class as MustInherit.
Nov 16 '06 #3

P: n/a
MrAnon wrote:
I have a class MySuperForm

Public Class MySuperForm
Inherits Form '' Yup, System.Windows.Forms.Form
Implements IMySuperForm
End Class

Public Interface IMySuperForm
Sub Show()
End Interface

In c# that would compile, but in VB.NET I need to declare which method
implements Show() but I can't because the method doesn't belong to me.
It belongs to Form.
Cut and pasted into VB'2003 and, after taking out the '>'s and pressing
Enter in a few choice places, the IDE gave me this ...

Public Class MySuperForm
Inherits Form '' Yup, System.Windows.Forms.Form
Implements IMySuperForm

' BINGO!
Public Sub Show1() Implements IMySuperForm.Show

End Sub

End Class

Public Interface IMySuperForm
Sub Show()
End Interface

In fact, Show1 doesn't even have to be Public, if you don't want it to be.

HTH,
Phill W.
Nov 16 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.