Information Technology Reference
In-Depth Information
Methods can also be function members of another user-defined type called a struct, which
is covered in Chapter 12. Most of what this chapter covers about class methods will also be true
for struct methods.
For example, the following code shows a simple method called MyMethod , that, in turn, calls
the WriteLine method several times:
void MyMethod()
{
Console.WriteLine("First");
Console.WriteLine("Last");
}
Code Execution in the Method Body
The method body is a block , which (as you will recall from Chapter 2) is a sequence of state-
ments between curly braces. A block generally contains the following:
￿Local variables
￿
Flow-of-control constructs
￿Method invoca ions
￿
Blocks nested within it
Figure 5-2 shows an example of a method body and some of its components.
Figure 5-2. Method body example
Search WWH ::




Custom Search