In most cases, more than one statement is needed to do a certain task; and often, the same task needs to be done more than once.
Instead of writing the same statements over, you can define a method where you write the sequence of statements only once, and call the method whenever you need to perform the task.
The following example shows how a method is typicaly defined.
void methodName ( ) {
... statements ...
}
sub methodName ( )
... statements ...
end sub
function methodName ( ) {
... statements ...
} |
|
C# |
VB |
JScript |
- The first statement explicitly declares that the following code is a method block. Each method must be given a unique name.
- The pair of parenthesis ( ) after the method name is used to accept values, called arguments, that may be passed on to the method for certain purposes, as shall be explained later.
- The sequence of statements follow the method name declaration.
NOTE: C# and JScript use braces { }
to specify the start and end of a method block, even if the method contains only a single statement.
After a method is defined, we can use it by simply calling its name.
... more on programming language syntax soon ...
ASP.NET Primer | Authoring an ASP.NET Page