Methods

A method is a class member that implements certain calculations or actions on an object or class.

method-declaration:

sub-declaration

function-declaration

sub-declaration:

attributesopt   method-modifiersopt

Sub   member-name ( formal-parameter-listopt )  ;   method-localsopt

Begin   method-body   End Sub   member-nameopt   ;

function-declaration:

attributesopt   method-modifiersopt

Function   member-name ( formal-parameter-listopt )  :   return-type   ;   method-localsopt

Begin   method-body   End Function   member-nameopt   ;

method-modifiers:

method-modifier

method-modifiers   method-modifier

method-modifier:

New

Public

Protected

Friend

Private

Shared

Virtual

Final

Override

Abstract

return-type:

type

member-name:

identifier

interface-type   .   identifier

method-locals:

method-locals-declarations

method-locals-declarations:

method-locals-declaration

method-locals-declarations   method-locals-declaration

method-local-declaration:

Var   local-variables   :   type   local-variable-initializeropt   ;

local-variables:

identifier

local-variables   ,   identifier

local-variable-initializer:

=   expression

=   array-initializer

method-body:

block

Method declaration is correct if all of the following are true:

When abstract methods are declared, only the method header is specified. The declaration of other methods includes the method body that contains operators executed when this method is invoked.

The name and formal parameters list of a method determine its signature.

Method Body

The method body consists of the operators block. Abstract methods do not have an implementation, and accordingly, the declaration of such methods does not include a body.

If a method does not return a value, it is not possible to use the Return operator in its body and specify the returned value.  When the return type of a method is not void, each return statement in that method's body must specify an expression of a type that is implicitly convertible to the return type.

Additional information is contained in the following subsections:

See also:

Classes