Asp tutorial. net c # Language Specification class and object method body and local variables
The method Body specifies the statements that will be executed when the method is called.
The method body can declare variables used only in this method call. Such variables are called local variable ).
The local variable declaration specifies the type name, variable name, and initial value.
The following example declares a local variable I with an initial value of zero and a variable j without an initial value.
Using system;
Class squares
{
Static void main ()
{
Int I = 0;
Int j;
While (I <10)
{
J = I * I;
Console. writeline ("{0} x {0} = {1}", I, j );
I = I + 1;
}
}
}
C # the value of a local variable must be obtained only after a definite value (definitely assigned) is assigned.
For example, if the initial value is not included in the declaration of I, the compiler will report an error for subsequent use of I, because I has not explicitly assigned values to these positions in the program.
You can use the return statement to control the caller returned to it.
In the return void method, the return statement cannot specify an expression.
In a non-void return method, the return statement must contain an expression for calculating the return value.