Comprehension and summarization of C # Learning notes---Functions (entry level)

Source: Internet
Author: User

* Content may not be in place, I hope that the small partners to find out, together in the IT this "pit" deeper and deeper, to do a deep program "ape"; late-night Hair Bo only chart progress and ... You know!!

1) function:

The main function is to make the code structure better.
a function is a program code module (a program segment) that implements a relatively independent function.
Four elements of a function: function name, input, output, Operation

* Some functions do not have input , the function name after the parentheses can not write things, but must have parentheses .
* Some functions do not return , do not write the data type on the left side of the function name, write void. (Just output to be displayed, not into "Main" function.) Direct output with void)

the formula for the function definition :

Static return type function name (formal parameter list)

{Function Body operation

}

Example: Static int[] Shuzu (int[] a)

{

for (int i=0;i<a.length;i++)

{

Console.WriteLine ("Please {0} judges rating", i+1)

A[i]=convert.toint32 (Console.ReadLine ());

}

return A;

} (randomly looking for a string of today's just-practiced functions)

2) Focus: argument list

Call Syntax:
Data type variable name = function name (argument list);
Example: Borrowing a previous example

1) A=shuzu (a);

The form participation argument must correspond (number, type)

Pass Value
Make a copy of the data of the argument and send it to the formal parameter of the function.
General basic types (Int,double,char,bool,datetime) are value types, and they are passed by default.

Transfer address
Pass the address of the argument to the formal parameter of the group function. The same data space is shared by the formal participation argument.
A generic reference type is a pass-through address. such as strings;

One, mark the players (marked "x" for error-prone points)

 static void Main1212 (string[] args) {int[] a = new int[10]; int max = 0, min = $, sum = 0;x-I forgot to assign a value to a variable//score a = Shuru (a); X-important commonly used//calculation MA            x = Max (a);            min = min (a);            sum = SUM (a); Output Shuchu (a,max,min,sum); X-comprehension is not very transparent} static void Shuchu (int[] a,int max,int min,int sum) x-vo            Use of the id {double AVG = 1.0 * (sum-max-min)/(a.length-2);        Console.WriteLine ("Remove a maximum score {0}, remove a minimum of {1}, the player's average is divided into: {2}", Max, Min, avg);                } static int[] Shuru (int[] a) {for (int i = 0; i < a.length; i++) x-i=0 reasons to remember {                Console.Write ("{0} judges scored:", i + 1);            A[i] = Convert.ToInt32 (Console.ReadLine ());   } return A;            return} static int Max (int[] a) {int zd = 0; Use of foreach (int b in a) *foreach {if(b > Zd)                {ZD = b;        }} return ZD;            } static int Min (int[] a) {int ZX = 10000;  for (int i = 0; i < a.length; i++) {if (A[i] < ZX) {ZX                = A[i];        }} return ZX;            } static int Sum (int[] a) {int ZF = 0;            foreach (int b in a) {ZF = ZF + B;        } return ZF; }    }}

That's all for today, and we'll finish the study tomorrow.

Comprehension and summarization of C # Learning notes---Functions (entry level)

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.