How to use C # functions

Source: Internet
Author: User

A function is an important part in any language, no matter what kind of program is composed of more or less functions. The use of a function, divided into declarations and calls two steps.

    • Declaration of a function
Static return type function name (argument list) {     function body}

The parameter list is in the form: parameter type parameter name, parameter type parameter name, ...

function names, argument lists, return types, function bodies are the 4 basic components of a function, where the function name and return type are the two parts that are indispensable to the function.

    • Call to function

Function name (parameter list);

The call to the function can be reached.

When a function is called: The calling function uses a parameter type and quantity and the function definition uses the type and number of parameters to keep one by one corresponding.

    • Formal parameters and arguments

Parameter: The argument used in the function definition.
Arguments: Parameters that are used when a function is called.

The formal parameter and the argument are two independent existence, the parameter change does not affect the actual parameter the original value, after the formal parameter obtains the value which the argument passes, the actual parameter change also does not affect the parameter the numerical value.

Static void Main () {    int11;    Console.Write (Numadd (A, b)); Static int numadd (intint  y) {    return x + y;}

In the above example, A and B are arguments, and x and y are formal parameters, and no matter how the A,B,X,Y4 variable changes, the values will not be affected by the number of variables passed.

How to use C # functions

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.