Relive the C # CLR notes summary
Font: [Increase decrease] Type: Reprint time: 2013-05-13 I want to comment
This article is to learn some of the previous C # CLR to do some notes, now take out and share with you, hope that friends can refer to
1: the. NET Framework consists of two parts: theCLR and the FCL.
2: In the CLR, all errors are reported through exceptions.
3: The IntelliSense function is mainly realized by parsing meta-data .
4: Allowing easy switching between different languages, and tight integration of various languages is a great feature of the CLR.
5: A method can only be run for the first time due to the JIT caused a certain performance loss , and subsequent calls to the method in the form of local code to run full speed.
6: The method signature specifies the number of parameters (and their order), the type of the parameter, whether the method has a return value, and, if there is a return value, the type of the return value.
7: Regardless of the language used, the behavior of the type is exactly the same, because the behavior of the type is ultimately defined by the CLR's CTS.
8: Use [Assembly:clscompliant (true)] to check CLS compatibility.
9: In the same assembly, the type is internal by default, and one principle is that Microsoft always chooses the least exposed keyword , such as the default private.
10: Each member of a type in the CLR is either a field or a method.
11: Answer file csc.rsp function, use/noconfig switch ignore local and global csc.rsp.
12: Meta data: Binary data blocks, consisting of several tables: divided into 3 categories:A: Definition table, B: List table, C: Reference table.
13: A managed PE file consists of 4 parts,PE32 (+) header, CLR header, meta data, IL.
14: An assembly is a collection of one or more type definition files and resource files.
15: Assemblies allow us to separate the logical and physical representations of reusable types, and if an assembly is not used, it will never be downloaded.
16: In order to generate a new assembly, all files from one referenced assembly must exist, but all the files of the referenced assembly do not necessarily exist when you run an application.
17: Assembly version Number format: Major version number, sub-version number, build number, revision number.
18:[assembly:assemblyculture ("De-ch")] Sets the language culture of the assembly to Swiss German.
19: Use MSI file to implement "Install as needed".
20: Weak-named assemblies all become problematic because several different assemblies may have the same weak name.
Page: "DLL Hell" Source: Shared DLLs are all copied to the System32 directory, the names of weakly named may be the same, and the last installation overwrites the previous assembly.
22: The ability to drag and drop an assembly into the GAC relies on the Windows Explorer Shell (extension) ShFusion.dll.
23: Under Command Window cmd, go to the GAC directory to see the structure of the GAC.
24: When you install the. NET Framework, you install two sets of replicas, one set of compilers/clr directories, and the other: the GAC subdirectory.
:ToString method defaults to this. GetType (). FullName.
The 26:gettype method is a non-virtual method, which prevents a class from overriding the method, concealing its type, and destroying security.
the namespace and the assembly are of little relevance .
28: All objects on the heap contain two additional members: the type Object pointer and the synchronization block index .
The GetType method of 29:system.object returns the address stored in the type Object pointer member of the specified object.
The 30:gettype method returns a pointer to the object's type object.
To: any data type supported directly by the compiler is called a primitive type .
32: In a variable that represents an instance of a value type, it does not contain a pointer to an instance, and the opposite variable contains the field of the instance itself.
33: The document calls all value types a struct or an enumeration.
34: If you know that the code you write will cause the compiler to repeatedly boxing a value type, then manually boxing the value type, the code will be smaller and faster.
35: Summary 34th: reduce the number of time-consuming steps to call wasted resources.
36: The use of interfaces allows us to change the field of a boxed object, in C #, the method of not using the interface is to achieve this. Because this approach is a bit around, it is not recommended to use a value type that needs to modify the field, in design mode, the value type is the immutable type.
37: Internally, the Equals method of ValueType uses reflection techniques to perform comparison of fields, because reflection is slow, so when defining your own value type, you should override the Equals method and do not call base. Equals. The specific rewrite steps are as follows:
A: if obj = = null–> false;
B: Parameter refers to different objects, false;
C: Each field is equal –>check, not equal (false)
D:true.
Because the correct override of the Equals method is more complex, where performance requirements are not very serious, it can be overridden.
38: When you need to modify a hash table's health value pairs, the correct way is to first remove and then Add.
39: Do not persist the hash code because the hash code is easily changed, for example a future version may use a different algorithm to calculate the hash code of the object.
40: The format of the metadata is independent of the programming language used by the source code, so the format of the metadata is the same, the metadata is the common information that all languages can generate and use, and is the key to the. NET Framework development platform, which allows for seamless integration between programming languages, types, and objects.
41: For any accessible member, it must be defined within a visible type.
PS: If you can't see the class, can you see what's Inside the class?
42: Visibility of type: public internal (default)
Visibility of Members: Public protected private (default)
: TheCLR requires that all members of an interface be public , that the interface is a contract, and that it makes sense for members to be public.
The 44:c# compiler requires that both the original member and the overriding member must have the same accessibility, and the CLR allows the member's accessibility constraints to be lower rather than higher. If a method of the parent class is protected, then the subclass can override this method by choosing a lower-bound
Public, but you cannot choose to constrain the stronger private.
The keyword static can only be applied to a class and cannot be applied to a value type (struct, enum) because the value type must be instantiated and there is no way to stop and block the procedure.
45: Static classes must inherit System.Object directly, because inheritance applies only to objects.
The static class cannot implement any interface , because only the instance of the class can invoke the method of the interface, but the static class cannot be instantiated.
47: Only static members can be defined, because static classes cannot be instantiated.
48: The compiler does not generate instance constructor methods in static class types.
The 49:c# compiler fully supports partial class (partial type) features, but the CLR does not support it at all, and even the CLR has no
The partial keyword.
50: For type fields: The CLR creates dynamic memory, which is JIT-compiled, when the type is first referenced.
For instance fields, the dynamic memory that holds the field is allocated when the type instance is created.
51: If a field belongs to a reference type and is marked as ReadOnly, the reference itself, not the object it refers to, cannot be changed.
52: A constructor is a special method that allows a type instance to be initialized to a valid state.
53: If there are multiple instance constructors, it is best to call the default parameterless constructor first, and then assign a value through the This keyword.
Public SomeType (int x,int y): this () {}
Si: All constructors of value types must initialize all fields of a value type , because any field of a value type must be initialized before reading.
The type constructor has at most one and never has parameters.
56: Because the CLR guarantees that the type constructor for each application domain executes only once and is thread-safe, it is best suited to construct
Singleton mode
57: If you want to execute some code when the application domain is closed, we can register a callback method in the System.AppDomain DomainUnload event.
58: When the compiler looks for operators of primitive types such as core values (Int32,int64) in the FCL, it generates IL directives for direct operations, so the core FCL type cannot define the cause of any operator overloading methods because the method invocation can affect efficiency.
The 59:CLR specification defines the conversion operator overloading method as public and static methods.
60: The params keyword can be used only for the last parameter of the method.
A: a property cannot be passed as an out or ref parameter to a method , but a field can. Because the nature of the property is getter and setter.
TheC # compiler only allows interfaces to define methods , because events, properties, indexers are essentially methods, so they are also allowed to be defined in the interface.
Relive the C # CLR notes summary