Read the summary and summary of learning hard c # LEARNING notes. 1,
I have the honor to hold a book-breaking activity in Learning Hard."Learninghard C # Study Notes" to feedback to netizens, 5 free booksI got a free book "LEARNING HARD C # LEARNING notes. NET has been developed for many years, but it has never been able to learn well systematically, especially C #5.0. Now, I am lucky to get this book to study, consolidate, and improve it. Thank you very much for Learning Hard!
After receiving the book, I spent about two weeks reading it, mainly in the evening and weekend, because the book explains C # knowledge from the beginning to the end, although I can't talk about any experts, I am familiar with and master the knowledge of C # earlier versions. Therefore, I will focus on the later sections (chapter 13 and later ), the speed is also compared. I generally like to summarize and summarize the important knowledge points in the book, so that I can review them later. Confucius said: It's time to learn new things and learn new things. Therefore, after reading this book, I feel it is necessary to summarize some articles based on the key points in the book and my usual experience, so that I can review them later, it is also a reference for beginners. There may be some deficiencies in this article due to differences in understanding. Please comment and give some suggestions to make progress together. Thank you!
I.. NETBasic
CLR: Common Language Runtime Library
CTS: General Type System
CLS: Common Language Specification
The Code managed by CLR is called managed code, otherwise it is called unmanaged code.
II.Types and variables
Data types include: Value Type and reference type
Value types include numeric, enumeration, and struct.
Reference types include: interface, class, Delegate, String, array
The Value Type allocates memory space in the stack and stores data;
The reference type allocates memory space on the heap and saves data, and saves the data address pointing to the heap in the stack;
Packing: Convert the value type to the reference type;
Binning: converts a reference type to a value type;
Constant: Const ID. It must be initialized during declaration and cannot be changed. It can be accessed by class name;
Variable:
Static: It is initialized once and continuously stored in the memory space and can be read and written repeatedly;
Readonly: initialization is only allowed in the Declaration or in the constructor of the class. It cannot be changed elsewhere;
Differences between Static Readonly and Const:
Static Readonly can be initialized in the constructor, but Const cannot;
Static Readonly allocates memory space during runtime, while Const allocates memory space during compilation;
3. Operators
The definition of operator overloading is as follows:
Public static opearator operator (type 1, type 2 );
Note: The access modifier of the operator overload method must be Public static
Iv. Conditions and loops
Conditional statement: 1. if-else 2. switch
Loop statement: 1. while 2. do-while 3.for 4. foreach
Jump statement:
Break: jump out of the loop or branch; continue: Skip this loop and continue executing the next loop;
Goto: Jump to the specified tag (not recommended );
Return: exit the method, and directly Return or Return the value, without limit to depth;
V. Category
Class access modifier
Public access is not restricted, and can be accessed either inside or outside the class in the same assembly or other assembly that references the Assembly;
Private access, which can only be accessed within the class;
Protected Access: only accessible within the class and its sub-classes;
Internal can be accessed inside and outside the class in the same assembly;
Protected internal can be accessed inside the class of the same assembly and inside its subclass;
Note: by default, no modifier is added, indicating access in the form of Internal
Sealed is Sealed and cannot be inherited;
Abstract: Must be inherited. If an Abstract member is present, override is required to override the member in the subclass;
Statict static seals, which cannot be instantiated and can not be inherited;
Elements defined in the namespace (class, interface, struct, Delegate, etc.) cannot be explicitly declared as private, protected, or protected internal
Constructor:
1. Reload is allowed. 2. If no declaration is made, the constructor without parameters and empty implementation is generated by default after compilation. 3. The constructor name is the same as the class name;
4. No return value;
Purpose: instantiate an object through the corresponding NEW constructor;
Static constructor:
1. Access modifiers cannot be used; 2. Only one non-argument constructor can be defined (I .e., reload is not allowed); 3. Only one request is executed;
Purpose: Initialize static members in the class;
Destructor:
Index indicator:
Definition method: modifier type this [index parameter list,…]
Note: The index indicator access modifier cannot be static.
Vi. Differences between classes and struct
1. The class is the reference type, and the struct is the value type;
2. the struct cannot be initialized when fields are declared, but must be initialized in the constructor without restrictions on the class;
3. The default non-argument constructor of the class does not exist after explicit declaration, and the struct cannot be explicitly declared, so it always exists;
4. structs can only implement interfaces, but cannot inherit classes or structs. classes can inherit classes or implement interfaces;
5. struct cannot be declared as abstact, sealed, or static, while classes can;
6. struct objects can be declared without new, but unassigned fields are unavailable. Classes must use NEW to instantiate objects;