March on 13

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.