VB.Net program to demonstrate the namespace with different complex types

Here, we are going to demonstrate the namespace with different complex types in VB.Net.
Submitted by Nidhi, on December 29, 2020 [Last updated : March 08, 2023]

Namespace with different complex types in VB.Net

Here, we will create a user-defined namespace that contains different data complex types like class, structure, and enumeration.

Program/Source Code:

The source code to demonstrate the namespace with different complex types is given below. The given program is compiled and executed successfully.

VB.Net code to create namespace with different complex types

'VB.net program to demonstrate the namespace with 
'different complex types.

Namespace MathNamespace
    Class AritheMatic
        Sub Add(ByVal num1 As Integer, ByVal num2 As Integer)
            Console.WriteLine("Addition is: {0}", num1 + num2)
        End Sub

        Sub Subtract(ByVal num1 As Integer, ByVal num2 As Integer)
            Console.WriteLine("Subtraction is: {0}", num1 - num2)
        End Sub
    End Class

    Structure Fact
        Sub CalculateFactorial(ByVal num As Integer)
            Dim fact As Integer = 1

            For i = num To 1 Step -1
                fact = fact * i
            Next
            Console.WriteLine("Factorial is: {0}", fact)
        End Sub
    End Structure

    Enum Colors
        RED
        GREEN
        BLUE
        BLACK
        WHITE
    End Enum

End Namespace

Module Module1

    Sub Main()
        Dim airth As New MathNamespace.AritheMatic
        Dim fact As New MathNamespace.Fact

        airth.Add(5, 10)
        airth.Subtract(50, 15)

        fact.CalculateFactorial(7)
        Console.WriteLine(MathNamespace.Colors.GREEN)
    End Sub
    
End Module

Output

Addition is: 15
Subtraction is: 35
Factorial is: 5040
1
Press any key to continue . . .

Explanation

In the above program, we created a namespace MathNamespace that contains a class AritheMatic, a structure Fact, and an enumeration Colors.

After that, we created a module "Module1" that contains the main() method, the main() method is the entry point for the program. Here we created the object of class and structure, then called methods to perform mathematical operations.

VB.Net Namespaces Programs »





Comments and Discussions!

Load comments ↻





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