C # examples of various definition methods

Source: Internet
Author: User

Although I have been studying C # For a while, I have learned from it because of the poor foundation. net framework cannot be used in depth. Now I will go back to the system and record some things in my blog. I will go back and look at it if I am idle and have nothing to do with it. I will deepen my grammar impressions, so experts will not have to look at it, it's all about basic things. It's just a note. Just like me, cainiao can come and take a look at the basics of their own syntax. It's not a good thing.

// Method with return value
// Call example:
// Int I = 2;
// Int result = Add (I );
// Console. WriteLine (result );
// Console. WriteLine (I );
// The output result is 3 and 2.
// The parameter is of the value type and the original value is not modified.
Public static int Add (int ToNumber)
{
Int sum = 0;
For (int I = 1; I <= ToNumber; I ++)
{
Sum + = I;
}
Return sum;
}

// Method without return value
// Call example:
// AddVoid (2 );
// The output result is 3.
Public static void AddVoid (int ToNumber)
{
Int sum = 0;
For (int I = 1; I <= ToNumber; I ++)
{
Sum + = I;
}
Console. WriteLine (sum );
}

// Reference type Method
// Call example
// Test obj = new Test ();
// AddObject (obj );
// Console. WriteLine (obj. Number );
// The output result is 3.
// Pass in the Number attribute of the obj object. The original attribute value is 1. After the object is passed in, its attribute is also modified.
// The reference type parameter is a data transfer address, not a value. The original values of all reference types are also modified.
Public static void AddObject (Test

Related Article

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.