Home >>VB.Net Built-in Functions >VB.Net Program to implement an interface in structure
Here, we will create a method declaration interface and then use the implementation keyword to implement the interface in the structure.
Program :
Below is the source code to demonstrate the basic interface. The program given is compiled and successfully executed.
'VB.net program to implement an interface in the structure.
Module Module1
Interface ISample
Sub Fun()
End Interface
Structure Sample
Implements ISample
Sub Fun() Implements ISample.Fun
' Method Implementation
Console.WriteLine("Fun() called inside the structure")
End Sub
End Structure
Sub Main()
Dim S As New Sample()
S.Fun()
End Sub
End Module
Explanation:
We created a Module1 module in the program above. Here, we built an ISample interface that contains the Fun() method declaration. Then we use the implementation keyword to implement the Fun() method in the Sample structure.
Finally, we created a Main() function, which is the program's entry point, here we created the Sample structure object and named the fun() method that will print a suitable message on the console screen.