- The second lesson: <<The third lesson The first lesson>>
Continuation of previous lesson we will review now the second type of types of functions:
2 - the function that receives the value of "parameter" but it does not return a value:
The following example illustrates the idea, beginning to create a function as follows:
(static void SecondMethod(int x
{
x = x * 10;
Console.WriteLine( x );
}
Just call the function remained even carry out its work but it seems that it must send a value for this function in order to do its job and of course we will send the value that will be of integer type ....
SecondMethod(5);
As soon as the program start, "according to the starting point is at the Main" it as soon as the compiler faces phrase SecondMethod (5); it looks for the function that bear this name and pass it the value in brackets which is 5,,,, No. 5 enters into the function to replace the variable x, and the calculation is performed and the result is printed on the screen ..
Since the functions can be its appeals for more than once within the program, try to write the following sentence recall:
Here we called the same function "SecondMethod", but with other value which is 6, will be repeated the same process above but with the change of the parameter and therefore will change the result:
This is the full program:
namespace ConsoleApplication1
{
class Program
{
static void SecondMethod(int x)
{
x = x * 10;
Console.WriteLine( x );
}
static void Main(string[] args)
{
SecondMethod(5);
SecondMethod(6);
}
}
}
The output will be as follows:
50
60
So that the first line in the output is the result of calling the function the first time, and the second line as a result of its appeals for the second time.
The final two types of functions followed up the next lesson.
"morse"
0 comments:
Post a Comment