VB.Net program to implement an interface in the structure

Here, we are going to learn how to implement an interface in the structure in VB.Net?
Submitted by Nidhi, on December 27, 2020 [Last updated : March 06, 2023]

Implementing an interface in the structure in VB.Net

Here, we will create an interface with method declaration and then implement the interface in the structure using the implements keyword.

Program/Source Code:

The source code to demonstrate the simple interface is given below. The given program is compiled and executed successfully.

VB.Net code to implement an interface in the structure

'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

Output:

Fun() called inside the structure
Press any key to continue . . .

Explanation:

In the above program, we created a module Module1. Here, we created an interface ISample that contains a declaration of the Fun() method. Then we implement the Fun() method in the Sample structure using the implements keyword.

At last, we created a Main() function, which is the entry point for the program, here we created the object of Sample structure and called the fun() method that will print an appropriate message on the console screen.

VB.Net Basic Programs »





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.