Interfaces

I'm new to using Interfaces.  I using  library that has an object defined as an interface.  How do I create/new an object of this type?
LVL 1
HLRosenbergerAsked:
Who is Participating?
 
AndyAinscowConnect With a Mentor Freelance programmer / ConsultantCommented:
oops, sorry.  The new should be used on a class that is based on the interface

dim obj as InterfaceX = new classX

with the following:
Public Interface InterfaceX
    Sub IFoo()
End Interface

Public Class classX
    Implements InterfaceX

    Public Sub IFoo() Implements InterfaceX.IFoo
        MessageBox.Show("Foo")
    End Sub
End Class
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
something like
dim obj as InterfaceX = new InterfaceX
0
 
HLRosenbergerAuthor Commented:
if I do that, I get "'New' cannot be used on an interface".
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
Fernando SotoConnect With a Mentor RetiredCommented:
Hi HLRosenberger;

An interface is a definition of what needs to be implemented in your code to fulfill the contract of that interface. Please see this Microsoft Documentation on Interfaces (Visual Basic) for more details.
0
 
HLRosenbergerAuthor Commented:
thanks.
0
 
Fernando SotoRetiredCommented:
Not a problem, glad to help.
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.