O'Reilly logo

Visual Basic .NET Programming Language, The by Paul Vick

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 10. Methods

A method is a collection of executable statements used to accomplish some task. Methods are the primary way to take action in a program.

Subroutines and Functions

A method is either a function or a subroutine. A subroutine performs some action and returns. For example:

Sub Main()
  Console.WriteLine("Hello, world!")
End Sub

A function, on the other hand, calculates a value that is returned to the caller when the function ends. When a function is declared, it specifies the type of the value that it returns in much the same way that a variable specifies its type. For example, the following function calculates the sum of two numbers and returns the result.

 Function Add(ByVal x As Integer, ByVal y As Integer) As Integer Return x + ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required