A. NET platform and C # language
1.. NET platform is an important component:
(1) flc– Framework class Library;
(2) clr– common language runtime;
2.. NET language has C#,F#,VB. NET and so on, C # is specifically for. NET platform to develop a language.
3.. NET version
2002. NET Platform release 1.0,2.0 release let. NET really fire up.
two.. NET Simple compilation of the program
1. The Assembly of C # consists of MSIL (Microsoft intermediate language).
2. Compile the generated EXE file double-click Run, the CLR runs concurrently, JIT under the CLR will convert the assembly's Microsoft intermediate language to the cost of platform CPU instruction and send instructions to the CPU to execute.
3. Through mono, you can achieve the cross-platform of. NET programs, which can be run perfectly on Linux,unix and other operating systems.
three. VS Usage Tips
Code snippet Editing Management: For example, the "CW" +table key can automatically output "Console.WriteLine ()".
Four Data type conversions
Interview question: What is the difference between the parse and convert conversions?
The convert conversion is actually called the Int.parse () method, except that the string is not NULL before the call and returns 0 if null.
Five Reference types and value types
Value type: The space in the variable that stores the data directly in the stack. For example, Char,bool, enumerations, structs, and so on.
Reference type: The variable is declared in the stack, the real object is stored in the heap, and the variables inside the stack store the address of the object. For example, string, array, class, and so on.
Six Array
Examples of programs:
1Staticvoid Main (String[] args)2{3//One-dimensional arrays4int[] A1 =Newint[1];//Dimension is 15//Multidimensional arrays6int[,] A2 =Newint[1,2];//Dimension is 27//Jagged arrays8int[][] A3 =Newint[1][];//Dimension is 19Ten a3[0] =Newint[3];//The definition needs to be re-instantiated when using array elements in a jagged array11 a3[0][0] = 1; A3[0][1] = 1; 13 a3[0][2] = 1; 15 Console.WriteLine (A1. Rank); 16 Console.WriteLine (A2. Rank); 17 Console.WriteLine (A3. Rank); 18}
Seven Overload
Conditions that make up the overload:
- The name of the method is the same;
- The number or order of the method parameters is different;
- Must be in the same class;
- Regardless of the return value;
Eight. params variable parameters
1. Variable parameters can only be used to decorate one-dimensional arrays.
2. These elements are automatically encapsulated as an array and passed at the time of invocation.
3. The variable parameter must be placed at the end of the parameter list.
Nine. Ref and out
Same point:
1. Both ref and out are parameters of the modified method, which must be preceded by a ref or out in front of the variable;
2. If a variable is modified by ref or out, it is not the value of the passed variable, but the address of the variable;
Different points:
1. Out must be assigned a value within the method, ref can modify its value or it can not be modified;
2. Out focuses on the output, and ref focuses on the modification;
3. The out can not be assigned an initial value until it is passed, because the out value is definitely assigned in the method;
4. Ref must have a value before it is passed, because the value of this parameter may be used in the method;
Examples of programs:
1 Static voidMain (string[] args)2 {3 inti =1;4 5 Add (i);6Console.WriteLine (i);//output is 17 8ADD (refi);9Console.WriteLine (i);//Output is 2Ten One int[] arr = {2,1,5,4,3 }; A intMax, Min; -Getmaxandmin (arr, outMax outmin); -Console.WriteLine (max+":"+min);//output is 5,1 the } - Static voidADD (inti) - { -i++; + } - Static voidADD (ref inti) + { Ai++; at } - Static voidGetmaxandmin (int[] arr, out intMax out intmin) - { - Array.Sort (arr); -Min = arr[0]; -max = Arr[arr. Length-1]; in } -}
Ten Access modifiers
Public: can be accessed from anywhere
Private: Accessible only in this class
Protected: Access in this class and in subclasses of this class
Internal: can only be accessed in the current assembly
11. Assembly
The intermediate product compiled by the compiler for further compilation by the CLR, which generally behaves as a dll or exe format in a Windows system, but note that they are completely different from the normal WIN32 executables. The Assembly must rely on the CLR for smooth execution.
12. Properties
Auto properties: public int age{get; set;}
Even if there is no logical judgment and try not to use automatic attributes, the efficiency will be lower. Try to write in the following form:
public int Age
{
get{return age;}
set{Age=value;}
}
12. placeholder
code example:
Console.WriteLine ("Please enter the number of {0}-{1} ranges", Min,max);
13. Construction Method
1. Construction method access modifiers are generally public, with no return value (not even void) The name of the method is consistent with the class name.
2. The construction method is automatically invoked at the time of creation and cannot be called manually by the programmer.
3. The construction method can have parameters.
4. The construction method can be overloaded.
5. The general method can be called within the constructor.
6. The constructor method can call other construction methods.
Examples of programs:
1 1 Public Dog (int age,string name)22 :this(age)3 3 {4this . name = name; 5 Console.WriteLine (""); 6 6 }
7. An implicit constructor.
14. Partial Classes
A class that is modified by partial is called a partial class or a partner class.
Application of partial classes: In WinForm applications, form classes and form design classes are the partner classes.
15. Null
1. Only the reference type's ability is null.
2. Null pointer exception reason: The reference type variable value is null.
15. constants and read-only variables
Const
1. Constant declaration must be assigned the initial value, once the constant declaration can not be changed;
2. Some data re-operation of the value will not change, we will define this as a constant, in order to improve the efficiency of the program operation;
ReadOnly
1. The value of the read-only variable is immutable;
2. The value of a read-only variable can only be changed in the constructor;
3. Const is the value to be determined at compile time, ReadOnly is the value to be determined at run time.
16. Enumeration
1. Enumerations are value types.
2. Each enumeration member corresponds to the numeric value of an integral type, which is incremented by default from 0.
3. The numeric value represented by the enumeration value can be cast, or the numeric value of an integer is converted to the enumeration value it represents.
4. You can manually assign each enumeration member a value of the integer type it represents.
5. Convert the string to the enumeration value Direction D = (Direction) enum.parse (typeof (Direction), str);
6. The value of the enumeration corresponds to a value of type int by default, you can specify the type of the numeric value by appending a colon to the name of the enumeration, but the specified type can only be integer.
Definition Example:
1 namespace Test 2 { 3 enum Direction 4 { 5 East, 6South , 7 West, 8 North 9 }
Examples of Use:
1 Static void Main (string[] args)2 {3 Direction dir = direction.east; 4 }
. NET Basics Review