Beginner's C # learning journey------01

Source: Internet
Author: User
Tags modifiers

One, Exchange two number of values

1  //Exchange A value of two numbers2             #regionMethod One3             intNUM1 =Ten, num2 = -;//two values to be exchanged4             intTemp//Temp Variable5temp =NUM1;6NUM1 =num2;7num2 =temp;8Console.WriteLine ("Num1 is: {0},num2 is: {1}", NUM1, num2);9 Console.readkey ();Ten             #endregion One  A  -  -             #regionMethod 2 the             intNUM1 =Ten, num2 = -, temp; -temp = NUM1 +num2; -NUM1 = Temp-NUM1; -num2 = Temp-num2; +Console.WriteLine ("Num1 is: {0},num2 is: {1}", NUM1, num2); - Console.readkey (); +             #endregion

Second,C # access modifiers

                          c# A total of 5 access modifiers: public, private, protected internal, protected internal.

Access modifiers Description
Public Public access. Not subject to any restrictions.
Private Private access. This class is restricted to access by members, subclasses, and instances.
Protected Secure access. This class and subclass access is limited, and instances cannot be accessed.
Internal Internal access. Access is limited to this item and cannot be accessed by others.
protected internal Internal protection access. Limited to this item or subclass access, other inaccessible

Third, the method

1. Method name
* Specification: Capitalize the first letter of each word

2. Return value of the method

* void: no return value. You cannot use return to return a specific value, but you can use return to terminate the current method
* Non-void: The value of the specified type must be returned with two exceptions: Double--float/int parent class type--return subclass

3. Invocation of the method

* Method of invocation:

Static: Addresses are 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 method, otherwise it is a non-static method

* Calls to methods in the same class:

1. Static can be directly called static

2. Static can not directly invoke non-static---static Mr. Cheng

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 called non-static

Overloads of the

             * Method:
                      * Prerequisite: The name of the method must be the same as
                      * condition: The parameter is different (two different: The quantity is different   or the    type is different)
                      * There is no relationship to the access type and return value type of the method

* Variable parameter: The number of parameter values can be any 0~ multiple
1. Variable arguments are called without having to encapsulate the passed value as an array, and the mutable parameter automatically creates an array of the appropriate length for you
2. If no arguments are passed, an array of length 0 is generated-index out of bounds
3. Parameter values for variable parameters must be of the same type
4. The variable parameter must be the last one in the parameter list

Not to be continued ...

Beginner's C # learning journey------01

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.