Function call related issues in C # code

Source: Internet
Author: User

The so-called function is a code that has a separate function and can be reused by name. The function should pay special attention to the declaration before the call. and the declaration position of the function must be in the class.

The syntax for a function declaration is the static void function name ()

{

function body (implemented when function is called)

}

The scope of a function is a variable that is valid only within the curly braces that he defines. Variables of different scopes have independent memory space, and when the scope ends, the variable disappears from memory. The identifiers in the function are the places in the code that you need to name yourself. (C # must consist of a numeric letter underscore and cannot begin with a number, and translation errors will occur if the requirement is not met)

The next step is related to the function call, which must be declared before the call,

The first is to declare a function with parameters, the function syntax is the static void function name (argument list)

                                                                                                                                                                        {

Comment Content

}

The parameter writing syntax is the data type parameter name, data type parameter name, ...

The function declaration syntax is public static void (formal parameter list) ... Parameters are the arguments used when the function is named

{

Comment Content

}

function call syntax function name (argument list) ... An argument refers to a parameter that is used when a function is called

When a function is called, the data of the argument is assigned to the parameter. (Arguments and parameters are independent of each other and do not affect)

The second is to declare a parameter with a return value

The return value of the function: The result that is produced after the run is finished. (return is used for returning results in the body of the function)

Use syntax: A return value or a variable or an expression. (When the function runs to the return statement, the function immediately returns the value after the return keyword, the result of a variable or an expression).

Call function syntax with return value: Function name (argument list)

The call to the function is an expression, and the return type is the same as the return type of the function declaration.

Through the full invocation of various functions can reduce the amount of code written, saving manpower and material resources, the most important thing is to reduce the error rate of code, and so on.

    

Function call related issues in C # code

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.