Implementation of Interface in VB.NET
In this article you will learn how to Implement of Interface in VB.NET.
Interface is a class which contains only the signatures of methods, events, properties. there implementation must be done in the derived class.
The major purpose of Interface is the implementation of multi-inheritance. The other use is reusability.
Code of Declare and implementation of an Interface.
Module Module1
Sub Main()
Dim cs As New Program.Calculate()
Console.WriteLine(cs.a + cs.b)
Console.ReadLine()
End Sub
Public Class Program
Private Interface ICalculate
Property a() As Integer
Property b() As Integer
End Interface
Public Class Calculate
Implements ICalculate
Private iA As Integer = 4
Private iB As Integer = 5
Public Property a() As Integer Implements Program.ICalculate.a
Get
Return iA
End Get
Set(ByVal value As Integer)
iA = value
End Set
End Property
Public Property b() As Integer Implements Program.ICalculate.b
Get
Return iB
End Get
Set(ByVal value As Integer)
iB = value
End Set
End Property
End Class
Public Sub Main(ByVal args As String())
Dim cs As New Calculate()
Console.WriteLine(cs.a + cs.b)
Console.ReadLine()
End Sub
End Class
End Module
Create an Visual Basic Console Application Write this code within module and then Debug.
The Output Screen is shows as: