Method signatures

All methods have a signature, which is defined by the method name and the data types of its parameters:

Public Function CalculateValue() As Integer

End Sub

In this example, the signature is f(). The letter f is often used to indicate a method or function. It is appropriate here because you do not care about the name of the function; only its parameter list is important.

If you add a parameter to the method, then the signature is considered changed. For instance, you could change the method to accept a Double:

Public Function CalculateValue(ByVal value As Double) As Integer

In that case, the signature of the method is f(Double).

Notice that in Visual Basic the return value is not part of the signature. You cannot overload a function routine by just having its return value's data type vary. It is the data types in the parameter list that must vary to utilize overloading.

Also note that the name of the parameter is totally immaterial; only the data type is important. This means that the following methods have identical signatures:

Public Sub DoWork(ByVal x As Integer, ByVal y As Integer)

Public Sub DoWork(ByVal value1 As Integer, ByVal value2 As Integer) In both cases, the signature is f(Integer, Integer).

The data types of the parameters define the method signature, but whether the parameters are passed ByVal or ByRef does not. Changing a parameter from ByVal to ByRef will not change the method signature.

0 0

Post a comment