1. Object-oriented polymorphism:
Virtual
Abstract
Interface
2. Value types, reference types
3. Value passing, reference passing (ref)
4. Interface
Int (C # recommended) int32
5. Enumeration-----Flags Enumeration
6. The Richter replacement principle
7. Exception try-catch-finally{}
function return value (modifier before function argument)
The Params variable parameter, regardless of several parameters, must appear at the end of the parameter list. You can pass an array of the corresponding type directly for a mutable parameter
classProgram {Static voidMain (string[] args) { //int sum= Add (10,20); //Console.WriteLine (sum);// -//Console.readkey (); //Console.WriteLine ("Hello, my name {0}, this year {1} years old, driving age: {2} years", "leaf Species", 25,0); //Console.readkey (); //int sum = ADD (ten, +); int[] Arrint = {1,3,5,7,9 }; //since the mutable parameter itself is an array, it is possible to pass an array directly in intsum =Add (Arrint); Console.WriteLine (sum); Console.readkey (); } //variable parameter Even if the user does not pass any parameters, it is possible (the array is an array of length 0, not NULL) if the parameter is not passed//A mutable parameter can only be present at the last of the method argument list Static intADD (params int[] nums) { intsum =0; for(inti =0; I < Nums. Length; i++) {sum+=Nums[i]; } returnsum; } //static int Add (int n, int m)//{ //return n + M; //} //static int Add (int n, int m, int l)//{ //return n + M + L; //}}
Ref is just an address, a reference address, and you can force a value pass to a reference pass.
Out allows functions to output multiple values;
classProgram {Static voidMain (string[] args) { intBasicsalary = +; //A parameter of ref, which requires that the passed in variable must be declared, and assigned a value. JIANGJINNUM1 (refbasicsalary); JiangjinNum2 (refbasicsalary); Baoxian (refbasicsalary); Console.WriteLine (basicsalary); Console.readkey (); } //bonus, excellent employee award Static voidJIANGJINNUM1 (ref intsalary) {Salary+= -; } Static voidJIANGJINNUM2 (ref intsalary) {Salary+= -; } Static voidBaoxian (ref intsalary) {Salary-= -; } }
It is not possible to change the above ref to out:
classProgram {Static voidMain (string[] args) { intbasicsalary; //A parameter of ref, which requires that the passed in variable must be declared, and assigned a value. JIANGJINNUM1 ( outbasicsalary); JiangjinNum2 ( outbasicsalary); Baoxian ( outbasicsalary); Console.WriteLine (basicsalary); Console.readkey (); } //bonus, excellent employee award//out parameter features: 1. Variables passed to out parameters, declarations do not need to be assigned, and assignments are meaningless//2. In the method where the out parameter is located, the out parameter must be assigned a value and be assigned before use//3. When there are multiple returns in the method it is worthwhile to consider out Static voidJIANGJINNUM1 ( out intsalary) {Salary+= -; } Static voidJIANGJINNUM2 ( out intsalary) {Salary+= -; } Static voidBaoxian ( out intsalary) {Salary-= -; } }
classProgram {Static voidMain (string[] args) { } Static voidM1 (ref intN) {n++; Console.WriteLine (n); } Static voidM2 ( out intN) {n=Ten; Console.WriteLine (n); } }
Exchange of two variables:
classProgram {Static voidMain (string[] args) { intNUM1 =Ten; intnum2 = -; Swap (refNUM1,refnum2); Console.WriteLine (NUM1); Console.WriteLine (num2); Console.readkey (); } Static voidSwap (ref intN1,ref intn2) { inttemp =N1; N1=N2; N2=temp; } }
out example