The call to the C # method says

Source: Internet
Author: User

Call to Method: Static: Address is assigned only once ... Static members are generated with the class, so when there are static members, non-static members are not yet generated, so they cannot be called to the
If the static keyword is added to the method, then it is still a non-static method
Ina method in the same classInvocation of:
1. Static can be directly called static, the current class can omit the class name
2. Static can not directly call non-static--Static Mr.
3. Non-static can be directly called static
4. If the static need to call a non-static member must use an instance member
5. Non-static can be directly non-static
methods of different classesCall:
1. Static use of the class. Static members
2. Non-static members use the class's instance object object. Method ()

Example:

public class Program

{

static void Main (string[] args)
{

Meditation method

#region Call method
int maxnum = Getmax (NUM1, num2);
Console.WriteLine ("Maximum value is {0}", Maxnum);
#endregion

Non-Silent

#region call the non-static method
Program model = new program ();
Model.test (NUM1, num2);
#endregion

}

#region ********** to obtain the maximum of two numbers (Trinocular operation) **********

<summary>

Get the maximum value of two numbers

</summary>

<param name= "NUM1" > First value </param>

<param name= "num2" > Second value </param>

<returns></returns>

public static int Getmax (int num1, int num2)

{

return NUM1 > num2? num1:num2;

}

#endregion

#region ********** The maximum value (non-static) of the two numbers **********

public void Test (int num1, int num2)

{

Non-static method for surface adjustment

int Maxnum=getmax (NUM1, num2);

Console.WriteLine ("Maximum value is {0}", Maxnum);

}

#endregion

}

The call to the C # method says

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.