When referencing, you need to add the REF keyword to the parameter and use
-
static bool Addnum (ref int val) //reference { ++val; return true; }
-
The concept of a parameter array, which can accept an array of that type, without limiting the size of the keyword params
-
static int GetLength (params int[] vals) //parameter array { int sum = 0; foreach (int val in vals) { sum + = val; } return sum; }
-
The concept of output parameters, similar to the parameter array, but can not be initialized when declaring
-
static int MaxValue (int[] intarray, out int maxindex) //output parameter { int MaxValue = intarray[0]; Maxindex = 0; for (int i = 1; i < intarray.length; ++i) { if (Intarray[i] > MaxValue) { MaxValue = Intarray[i];
maxindex = i; } } return maxValue; }
- Delegate delegate: the declaration of a delegate is similar to a function, but without the body of the function, and the delegate keyword is used. The declaration of a delegate specifies a return type and a list of parameters
-
Delegate Double processdelegate (double param1, double param2); Static double Multiply (double param1, double param2) { return param1 * param2; } Static double Divide (double param1, double param2) { return param1/param2; } static void Main (string[] args) { processdelegate process; string input = Console.ReadLine (); if (Input.compareto ("M") = = 0) { process = new Processdelegate (Multiply); } else { process = new Processdelegate (Divide); } Double param1 = 3.123; Double param2 = 23.12; Console.WriteLine ("{0}", Process (param1, param2)); }
- Specifies that the class is abstract, cannot be instantiated, can only inherit, and may have abstract members
-
Abstract class MyClass1 { }
- Specifies that the class is a sealed sealed and cannot inherit
-
Sealed class MyClass2 { }
- Member definitions
-
- Public members can be accessed by any code
- Private members are accessed by code in the class
- Internal members can only be accessed by code inside the assembly that defines it
- Protected members can only be accessed by code in a class or derived class
- The virtual method can override
- The abstract method must be overridden in a derived class of a non-abstract class
- The override method overrides a base class method
- The Extern method definition is placed elsewhere
C # programming Study #1