ARTICLE

Method Signatures in VB.NET

Posted by Manish Tewatia Articles | Visual Basic Language August 16, 2010
In this article I will explain you about Method Signatures in VB.NET.
 
Reader Level:

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 Integer, ByVal y As Integer)
    End Sub    ' MyFunc (integer, integer)

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

    Function MyFunc(ByVal x As Integer) As 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.

Login to add your contents and source code to this article
share this article :
post comment
 
Nevron Diagram
Become a Sponsor
PREMIUM SPONSORS
  • The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Nevron Diagram
Become a Sponsor