VB Functions

VB Functions

A VB.NET function is defined using the Function/ End Function keywords. The function is invoked by using it.

As with subs the function name must follow the naming convention of variables.

Function names may be used in uppercase or lowercase and invoked in either case.

Functions are used to return a single value.

                                                

Functions are defined as having a data type (the data type of the value that is returned). If one is not provided, it will default to type Object. Note that with Option Strict On, you must provide an 'As' clause.

This Integer function:



returns an Integer, while this one won't compile with 'Option Strict On' or with it off, will return an Object:



The value that the function has calculated is returned with the Return statement.

Functions must provide a value as part of the Return statement.

It is an error to define a function without a Return statement.

Functions may not be defined inside of other functions, or subs.

Functions may call other functions, or itself for recursive calls.



As with Subs, functions may be overloaded using different parameter signatures.

posted @ 2015-06-17 00:13  xymum  阅读(131)  评论(0编辑  收藏  举报