Pages

Men

rh

7/01/2012

How to work with an interface in VB.NET?
The following code demonstrates the ability to work with an interface. An interface defines a method's name and not it's contents.


Imports System
Imports Microsoft.VisualBasic
Public Interface NewInt
Sub Mysub()
Function MyFun() As String
End Interface
Class myclass Implements MyInt
' Implementing the above defined interface, need to use the keyword implements to use the interface

Shared Sub Main()
Dim mc As New myclass()
mc.Mysub()
End Sub
Sub Mysub() Implements NewInt.Mysub
MsgBox("Hello from INterfaces")
End Sub
Function MyFun() As String Implements NewInt.MyFun
dim str as string
str="hello matey"
return (str)
End Function
End Class

No comments :

Post a Comment