Total .NET Analyzer Rule Documentation  

NoMethodReturn Rule

Do not use functions without a return value.

Remarks

Functions should always return a value. Unlike the C# compiler, the Visual Basic compiler does not enforce this rule, and allows you to omit the return value. This is generally bad programming practice, and can indicate logic problems in your application.

The following examples show potential issues that may be indicated by a function without a return value:

1. The code should return a value, but the return statement is omitted due to a coding or logic error:


Function AddCustomer (Name As String) As Integer
' This code should return the customer number of the customer added.
Dim NewKey As Integer
NewKey = AddToTable (Name)
End Function

2. The original code design required a return value, but this need was later eliminated due to a design change. If the original function was not modified to be a subroutine, it may cause confusion in code reviews.

Resolution

In Visual Basic code, you should use a Function if your method is required to return a value, or a Subroutine if your code does not have a return value.

See Also

Function Procedures