VB.NET Method Signatures

In this article I will explain you about Method Signatures in VB.NET.
  • 4843

Methods, constructors, indexers, and operators are characterized by their signatures. A signature makes a method look unique to the C# compiler. The method name and the type and order of parameters all contribute to the uniqueness of signatures. 

Signatures enable the overloading mechanism of members in classes, structs, and interfaces. 

A method signature consists of the name of the method and the type and kind, such as value or reference. A method signature does not include the return type, nor does it include the params modifier that may be specified for the last parameter. 

A constructor signature consists of the type and kind, such as value or reference. A constructor signature does not include the params modifier that may be specified for the last parameter. 

An indexer signature consists of the type. An indexer signature does not include the element type. 

An operator signature consists of the name of the operator and the type. An operator signature does not include the result type. 

The example below illustrates the signature concept. 

Example of Signatures class

    Sub MyFunc()
    End Sub    ' MyFunc ()

    Sub MyFunc(ByVal x As Integer)
    End Sub    ' MyFunc (integer)

    Sub MyFunc(ByRef x As Integer)
    End Sub    ' MyFunc (ByRef As integer)

    Sub MyFunc(ByVal x As IntegerByVal y As Integer)
    End Sub    ' MyFunc (integer, integer)

    Function MyFunc(ByVal s As StringAs Integer
    End
 Function    ' MyFunc (string)

    Function MyFunc(ByVal x As IntegerAs Integer
    End
 Function    ' MyFunc (integer)

    Sub MyFunc(ByVal a As String())
    End Sub    ' MyFunc (string())

    Sub MyFunc(ByVal ParamArray a As String())
    End Sub    ' MyFunc (string())

MyFunc(ByVal x As Integer), MyFunc(ByRef x As Integer) are all unique signatures. The return type and the params modifier are not part of a signature, and it is not possible to overload based solely on return type or on the inclusion or exclusion of the params modifier. 

Notice that there are some errors for the methods that contain duplicate signatures like MyFunc(
ByVal x As Integer) and MyFunc(ByVal a As String()) whose multiple signatures differ only by return type. 

Conclusion

Hope this article would have helped you in understanding Method Signatures in VB.NET.

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.