CSHARP Language Specification
First, the basic
1. Specification:
In addition to constants, all variables are named by the hump, and others are named by Pascal.
2. Compiling:
The CS file is first compiled into MSIL by csc.exe. When you double-click the EXE, the CLR's JIT (just in time) compiler compiles the CPU instructions again.
csc position (e.g.): C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe
csc command (e.g.):csc/t:library Acme.cs (compiled into class library) Csc/r:acme.dll Test.cs (compiled after referencing acme.dll)
NGen position (e.g.): C:\Windows\Microsoft.NET\Framework\v4.0.30319\ngen.exe (JIT effect possible)
NGen command (e.g.): NGen install D:\SystemTool\HelloWorld.exe (remark: exe mode)
3. Object-oriented (object-oriented object-oriented Programming: object-oriented-programming):
The class is abstract and the object is concrete.
destructor: ~classname () {}. Actually, the Finalize () method that overrides the base class
4. Variables:
Member Variable: There is an initial value by default. string->null,int->0,bool->false
Local variables: You must assign a value before using it.
5. Package:
A. fields are encapsulated into attributes B. Method parameters are encapsulated into classes C. method Reuse D. Encapsulation into class library
6. Inheritance:
Uniqueness, transitivity
constructors do not inherit.
7. Polymorphism:
The a.vitual and override methods can be overridden
B.abstract method
C. Interface
8. Access Modifiers:
Member access modifiers:
Private: In the current class
Protected: Within and subclasses of the current class
Internal: In the current assembly
Protected internal: Inside the current assembly or within the current class and subclass
Public: All Can
Access modifiers under the namespace:
Only public and internal are allowed, but Microsoft internal uses private.
9. Static:
Static as a. Stati modifier that differs from polymorphism.
Static classes: cannot be instantiated, members are static members, can have const constants
Static members: Static members are assigned values in static constructors when they are assigned an initial value.
Static constructors: Called only once before the class is used for the first time. Cannot have modifiers and cannot be overloaded.
10. Value types and reference type values are passed with reference passing:
Value type: An int double struct, such as an implicit inheritance valuetype.
Reference type: An array of string classes implicitly inherits an object.
Value passing: The default is value passing.
Reference passing: adding ref to a method parameter is a reference pass.
11.SOLID:
Single: Sole responsibility
Open: Develop closed
Lis: Richter Replacement
Interface: interface separation
Depend: Dependency Inversion
The solid principle of object-oriented design
12. Interface:
A. The method can only be defined in the interface.
B. Members of an interface cannot have modifiers. Default is Public
13. Implement interface and display implementation interface:
A class implements both an interface and a display implementation interface.
Display implementation interface: When the interface is called, the method that displays the interface is called
Implement interface: The default implementation of the method to implement the interface.
14. Type conversion:
Implicit conversions: Types that have a large range when the type of a small range is turned.
Cast: Converts with (type name) or as when the specified large range of type objects can be turned to a small range type
Convert: Semantic transformations
Parse: Convert other types to numeric types
15. Unit:
1byte = 8bit
1KB = 1024byte
Int32 = Int:4byte
16. Exception Handling:
Error type: syntax error/logic error/Run error
Throw : Execution in Catch is the continuation of the exception.
In try-catch-finally, pay attention to the problem of return. The essence is to compile the return to the bottom. You can see that the return value is accepted by a separate variable by the Decompile tool.
17. Parameter modifiers:
Params: Variable parameters
Out: Outgoing parameters
Ref: Reference passing, in essence, when passing the value of a parameter, the memory address of the variable is passed
18. String:
1. String immutability: The strings in the actual double quotes are constants. A constant of a common declaration, a variable that declares a constant, accepts a constant.
2. String detention Pool: It is because of the immutability of the string, so the technique of this pool is put forward, the actual thing is to regard the contents of the string as the key, the address of the string as the value.
3.StringBuilder: Be sure to use the object when the string is stitched. Otherwise, the string object will be created continuously. And it is highly recommended that the initial value be given.
C # string Detention pool mechanism
19. Garbage Collection GC:
Recycle object: A Heap object in managed resource memory.
Payback time: not sure
Garbage collection is divided into 3 generations. When the first generation of space is full, the first generation of resources is recycled and the objects that are not recycled are moved to the second generation. And so on. It is highly recommended that manual garbage collection be made.
20. Collection:
A set and an array surface on which one is an indefinite length of a fixed length. An array is maintained internally by the actual set of elements. When an element is added, a new array is re-
Common collections:
ArrayList list<t>
Hashtable dictionary<t,t>
Stack Stack<t>lifo
Queue queue<t>
Microsoft recommends the use of a collection of generic classes. The essential reason is also the reduction in the number of packing and unpacking.
21. Packing and Unpacking
Packing unboxing occurs between parent and child classes.
Boxing: The value type is converted to a reference type. An interface that is often converted to an object, a value type implements.
Unpacking: The reference type is turned into a value type. Often occurs in cast-to-value types
22.Path File Directory FileInfo DirectoryInfo Stream StreamWriter StreamReader
Path file directory file information directory flow write stream read streams
In the form of a stream, the pressure on the device will be reduced. Do not perform subsequent actions until you have read them all at once.
23. Encoding
ASCII GB2312 GBK UNICODE UTF-8
Encoding.getencodings () Take all the computer code
The actual string stored on the computer is a number that is stored as byte[].
The reason for garbled is that the stored code and the read encoding inconsistency caused by the
24. Serialization
Serialization step: Create a serializer, serialize, or deserialize.
XML Serialization: XmlSerializer Class (System.Xml.Serialization)
JS Serialization: JavaScriptSerializer Class (System.Web.Script.Serialization)
Binary serialization: BinaryFormatter Class (System.Runtime.Serialization.Formatters.Binary)
Serialization: Saves the object state to the storage device.
25. Commission/Event
The nature of a delegate is a type
An event is a delegate object, essentially a private delegate object and 2 public methods. So events can only be called inside the class!
26. Anonymous
Anonymous method: Delegate (parameter) {method body} is used to assign values to delegate objects, essentially a compiler has a name.
LAMBDA: statement: (parameter) =>{method body} expression (only one argument, method body only a word) such as:x=>x+2;
Anonymous type example: new {Code = Viewbag.code}; The properties of the anonymous type are read-only! Fields of the intrinsic anonymous type are private readonly, encapsulated as read-only properties.
27. Generics
Generic support: Class method Delegate Interface
Generic constraint: Where t:class struct new () class name Interface name
28. Extension methods
Extension method: Static class static method The first parameter type is the type to extend
The essence is that the compiler uploads the extended type as a parameter to the static method.
29. Assemblies
. NET-generated EXE and DLLs are assemblies.
Includes type metadata, assembly metadata, resource files, MSIL intermediate languages.
Public assembly are in the GAC, so when compiling, the default imported assemblies are not output.
30.Type Assembly
Describes the type of the class. With the type object, you can instantiate an object of the type that this type refers to.
Type: by typeof (class name), GetType (object name)
Assembly:Assembly.LoadFrom (assembly name) returns a Assembly object. GetType (the qualified name of the Class) gets the type object of the specified class.
To create an object from type: Activator.CreateInstance (type object name)
31.XML
Extensible Markup Language: Case sensitive, a root node, attribute value double quotes, CDATA areas, annotations and HTML, the document declaration is encoded and the actual encoding is consistent.
32. Deep copy Shallow copy
A deep copy is a copy of all the members in memory. A deep copy can be completed by serialization.
Shallow copy: In addition to the deep copy, is a shallow copy, MemberwiseClone () can be copied directly.
CSHARP Language Specification