Overloading in VB.NET

What is overloading in VB.NET?

Explanation

Over loading VB.NET

Overloading in visual basic.net is the method by which a property or a method takes different forms at different instances. It can also be termed as "Polymorphism".
Example:

Module Module1
Public Class mul
Public a, b As Integer
Public c, d As Double
Public Function mul(ByVal a As Integer) As Integer
Return a
End Function
Public Function mul(ByVal a As Integer,
ByVal b As Integer) As Integer
Return a * b
End Function
Public Function mul(ByVal d As Double,
ByVal c As Double) As Double
Return d * c
End Function
End Class
Sub Main()
Dim res As New mul
System.Console.WriteLine
("Overloaded Values of Class Mul is::")
System.Console.WriteLine(res.mul(10))
System.Console.WriteLine(res.mul(20, 10))
System.Console.WriteLine(res.mul(12.12, 13.23))
Console.Read()
End Sub End Module
Result:

Overloaded values of Class Mul is:
10
200
160.3476
Description:

In the above overloading example the same function mul is called to perform different operations based on the arguments as well as on the datatype.

Visual Basic Tutorial


Ask Questions

Ask Question