What is this in VB? (from C#)

Trying to write this correctly from C#

1)  public interface IMyPage { void MyPublicMethod(); }

2)
public partial class MyPage : Page, IMyPage
{
...
public void MyPublicMethod() { ... }
}

3)
((IMyPage)this.Page).MyPublicMethod().

Thanks
LVL 2
born4codeAsked:
Who is Participating?
 
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
I'm not sure what Page is...are you inheriting from it or is it another Interface?

    Public Interface Page
        Sub MyPublicMethod()
    End Interface

    Public Interface IMyPage
        Sub MyPublicMethod()
    End Interface

    Partial Public Class MyPage
        Implements Page, IMyPage

        Public Sub MyPublicMethod1() Implements Page.MyPublicMethod

        End Sub

        Public Sub MyPublicMethod() Implements IMyPage.MyPublicMethod

        End Sub

    End Class

In VB you need to explicitly tell what method implements each piece of what Interface "contract".  As the example above shows, you can then easily handle it when two Interfaces have the same method name.

Not sure what you're doing in (3)...?

    Public Sub foo()
        Me.MyPublicMethod()
    End Sub
0
 
jononsterCommented:
Point 3 would be:

CType(Me.Page,IMyPage).MyPublicMethod
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
You shouldn't need to do any casting to call "MyPublicMethod" though...

If the class "is a" IMyPage because it implements that Interface then you should just be able to call it without any casting no?

I think C# is pickier and you need all the casting to appease the compiler.  You may need to go such antics if Option Strict is On in VB.
0
 
born4codeAuthor Commented:
Actually, the code is on different pages... i was lumping them.

It's good.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.