30. Try to implement CLS compatibilityProgramSet.
Prefer CLS-compliant assemblies.
Two rules must be followed: 1. the types of parameters and return values on all public and protected members must be CLS compatible [Assembly: clscompliant (true)]; 2. other public or protected members that are not compatible with CLS must have synonymous members (E. g: After operator + is overloaded, You need to define another synonymous add method to use the add method in CLS-compatible programs ).
31. Implement short and concise functions as much as possible.
Prefer small, simple functions.
C # The Compiler only sets C #CodeCompiled into il assembly, these assembly must be executed by JIT further compiled into the local code processed by the CPU before it can be executed. Small functions can be easily processed by JIT compiler in stages. Small functions are more likely to be inline by candidates. Of course, it is not small enough: A simple control process is also very important. JIT can easily store local variables with registers when processing simple branch control in a function. The smaller the method, the more likely it will be inline. Any virtual method or function containing try/catch blocks cannot be inline.
32. Implement as small and cohesive assembly as possible.
Prefer smaller, cohesive assemblies.
Large assemblies require more CPU time to load. splitting into small assemblies can enable the overhead during program startup to be processed in stages. However, the overhead between assemblies is, CLR needs to adjust the function entry address and perform security verification (all code in the same assembly has the same level of trust ). C #/. NET is designed with components as the core idea. We should also design the Assembly size according to the idea of components when building an assembly.
33. Restrict the visibility of types.
Limit visibility of your types.
For each type, the accessible level should be restricted as much as possible when the function is met. Reduce visible content by implementing public interfaces on the class to expose the content that must be exposed. Creating an internal class (internal class, which can only be visible within the Assembly) is a frequently used method to limit the visible range of types.
34. Create a large-granularity Web APIs.
Create large-grain Web APIs.
When you use a web service, or. NET remote interaction, the most expensive overhead is when objects are transmitted between two remote machines, so we need to weigh the session frequency between the two machines and the packet size during the session.