Information Technology Reference
In-Depth Information
The Structure of a Method
Essentially, a
method
is a block of code with a name. You can execute the code by using the
method's name. You can pass data into a method and receive data as output.
As you saw in the previous chapter, a method is a function member of a class. Methods
have two major sections, as shown in Figure 5-1—the method header and the method body:
The
method header
specifies the method's characteristics, including the following:
-
Whether the method returns data
-
The name of the method
-
What types of input can be passed to the method
The
method body
contains the sequence of executable code statements. Execution starts
at the first statement in the method body and continues sequentially through the
method.
Figure 5-1.
The structure of a method
The following example shows the form of the method header. I will cover each part in the
following pages.
int MyMethod ( i
nt intpar1, string strpar1
)
↑
↑
↑
Return
Method
Parameter
type
name
list