ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

VB.Net program to create an alias of a namespace

Here, we are going to learn how to create an alias of a namespace in VB.Net?
Submitted by Nidhi, on December 29, 2020

Here, we will create a user-defined namespace that contains a nested namespace, here we will create the alias of the namespace.

Program/Source Code:

The source code to create an alias of the namespace is given below. The given program is compiled and executed successfully.

'VB.net program to create an alias of a namespace.

Imports MyAlias = ConsoleApplication1.MathNamespace.Nested

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

    Namespace Nested
        Class 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 Class

    End Namespace
End Namespace

Module Module1

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

        airth.Add(5, 8)
        airth.Subtract(40, 15)

        fact.CalculateFactorial(4)
    End Sub
    
End Module

Output:

Addition is: 13
Subtraction is: 25
Factorial is: 24
Press any key to continue . . .

Explanation:

In the above program, we created a namespace MathNamespace that contains a nested namespace nested. Both namespaces contain classes. And each class contains methods.

Imports MyAlias = ConsoleApplication1.MathNamespace.Nested

Using the above code, we created the alias for the nested namespace. Then we can access the class using the alias name.

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 both classes and then called methods to perform mathematical operations.

VB.Net Namespaces Programs »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.