Pass value: four different ways
1, no return value, no input value (no return value, no value can be assigned)
2, no return value, with input value
3, there is a return value, no input value (there is a return value, must be assigned, and requires the output statement to display)
4, with return value, with input value
Example: Ask 1+ ... +n's and.
Four methods:
1, no return value, no input value
<summary>
This is a summation function, no return value, no input value
</summary>
public void H ()
{
Console.WriteLine ("Input variable N:");
int n = Int. Parse (Console.ReadLine ());
int a = 0;
for (int i = 1; I <= n; i++)
{
A + = i;
}
Console.WriteLine (n+ "The summation is:" +a);
Console.ReadLine ();
}
2, no return value, with input value
<summary>
This is a summation function, there is no return value, there is an input value
</summary>
<param name= "n" ></param>
public void H (int n)
{
int a = 0;
for (int i = 1; I <= n; i++)
{
A + = i;
}
The sum of Console.WriteLine (n +) is: "+ a";
Console.ReadLine ();
}
3, with return value, no input value
<summary>
This is a summation function, with a return value, no input value
</summary>
<returns></returns>
public int HH ()
{
Console.WriteLine ("Input variable N:");
int n = Int. Parse (Console.ReadLine ());
int a = 0;
for (int i = 1; I <= n; i++)
{
A + = i;
}
return A;
Console.ReadLine ();
}
4, with return value, with input value
<summary>
This is a summation function, with a return value, with an input value
</summary>
<param name= "n" ></param>
<returns></returns>
public int hh (int n)
{
int a = 0;
for (int i = 1; I <= n; i++)
{
A + = i;
}
return A;
Console.ReadLine ();
}
March on 13