High-quality Code Methods

Source: Internet
Author: User
Tags thread stop

Chapter 2 Basic Language element 1: Correct operation string/22: use default transformation method/63: differentiate between forced transformation and as and is/94: TryParse and Parse./1st: use int? To ensure that the value type can also be null/156: The difference between readonly and const/167: use 0 as the default value of enumeration/198: avoid providing explicit values for enumeration elements/209: Customary overload operator/2210: consider whether to implement comparator/2311: differential treatment = and Equals/2712 when creating an object: when rewriting Equals, you also need to override GetHashCode/2913: Format String for Type output/3214: Correct implementation of shap copy and deep copy/3615: use dynamic to simplify reflection Implementation/40 chapter 2nd set and LINQ/4316: when the number of elements is variable, arrays should not be used/4317: In most cases, use foreach for loop traversal/4518: foreach cannot replace for/5119: use more effective objects and set initialization/5320: Use a generic set instead of a non-generic set/5421: select the correct set/5722: ensure the thread security of the Set/6123: Avoid using List <T> as the base class of the custom set class/6424: The iterator should be read-only/6725: exercise caution when writing a set attribute/6826: use an anonymous type to store the result of a LINQ query/7027: Use a Lambda expression/7328: understanding the difference between latency evaluation and active evaluation/7529: difference between IEnumerable <T> and IQueryable <T>/7830: replace the comparator and iterator in the set with LINQ/8031: Avoid unnecessary iterations in the LINQ query/83 chapter 3rd generics, delegation, and events/8632: always give priority to generics/8633: avoid declaring static members in generics/8834: Set constraints for generics/9035: use default to specify the initial value for a generic type variable/9236: Use the delegate declaration in FCL/9437: Use Lambda expressions instead of methods and anonymous methods/9638: Be careful with the trap in the closure/9939: understand the essence of Delegation/10340: Use the event keyword to apply protection to the Delegate/10641: implement the standard event model/10842: use generic parameters to be compatible with the immutability of generic interfaces/10943: make the generic parameters in the interface support covariant/11144: Understand the covariant in the delegate/11245: Specify the inverter/114 chapter resource management and serialization for the generic parameters/4th: explicit resource release must inherit the interface IDisposable/11647: provide implicit cleanup/11948 In The Terminator even if an explicit release method is provided: the Dispose method should be allowed to be called multiple times/12049: a protected virtual method should be extracted in the Dispose mode/12150: managed resources and unmanaged resources should be treated differently in the Dispose mode/12351: the type with releasable fields or local resources should be releasable/12452: release resources in a timely manner/12553: if necessary, assign null/12754 to reference unused objects: unserializable field annotation for useless fields/13155: reduce serializable fields by using custom features/13656: Use the inherited ISerializable interface to control the serialization process more flexibly/13757: the sub-type implementing ISerializable should be responsible for the serialization of the parent class/140 chapter 5th exceptions and custom exceptions/14458: Return Error code instead of throwing exceptions/14459: do not trigger exceptions in inappropriate cases/14760: Use Inner Exception/15061 when re-triggering exceptions: Avoid writing Invalid code in finally/15162: Avoid nested exceptions/15763: avoid "eat" Exception/16064: Add Tester-Doer mode to the loop instead of placing try-catch in the loop/16165: always handle uncaptured exceptions/16266: capture exceptions in multiple threads correctly/16667: use custom exceptions with caution/16868: From System. exception or other common basic exceptions derived from Exception/17069: Use finally to avoid resource leakage/17270: avoid record exceptions at lower call stacks/Chapter 175 Asynchronization, multithreading, tasks, and parallelism/6th: differentiate Asynchronization and multithreading application scenarios/17771: use semaphores/18073 in thread synchronization: avoid locking inappropriate synchronization objects/18474: guard against thread IsBackground/18875: guard against thread not starting immediately/18976: alert Thread priority/19177: correct Thread stop/19378: avoid too many threads/19479: Use ThreadPool or BackgroundWorker to replace Thread/19680: Use Task to replace ThreadPool/19881: use Parallel to simplify the use of tasks in the synchronization state/20282: Parallel to simplify but not equal to the default behavior of tasks/20483: Be careful with traps in Parallel/20584: Use PLINQ/20885: exception Handling in Task/20986: Exception Handling in Parallel/21487: differentiate the thread model of WPF and WinForm/21688: Parallel is not always faster/22089: exercise caution when using the lock in the parallel method body/222 Part 2 architecture Chapter 2 member design/7th: do not provide a public constructor for the abstract class/22690: visible fields should be restructured into properties/22692: exercise caution when using arrays or sets as properties/22793: constructor should initialize main attributes and fields/22894: Treat override and new/22995 differently: avoid calling a virtual Member/23596 In the constructor: the member should give priority to exposing the base type or interface/23697: give priority to passing the base type or interface as a parameter/23798: use params to reduce repeated parameters/23799: Do not use subclass parameters during rewriting/238100: no difference between static methods and instance methods/239101: Use extension methods, add method to existing type/Chapter 240 Type Design/8th: application scenarios for distinguishing interfaces and abstract classes/243102: application scenarios for distinguishing combinations and Inheritance/243103: replace conditional statement with polymorphism/248105: use private constructor to strengthen Singleton/251106: Add static constructor for static classes/253107: differentiate between static classes and Singleton/255108: mark the type as sealed/255109: exercise caution when using nested classes/256110: use classes instead of enum/257111: Avoid bidirectional coupling/260112: Abstract objects in the real world as classes, labeling reusable objects is the namespace/Chapter 262 security design/9th: before declaring a variable, consider the maximum value/264113: MD5 is no longer secure/264114: verify file tampering through HASH/268116: Avoid using asymmetric algorithms to encrypt files/269117: use SSL to ensure data security in communications/273118: Use SecureString to save secret strings such as keys/284119: do not use your own encryption algorithm/289120: specify a strong name for the assembly/289121: set running permissions for the application/291 Part 3 encoding specifications and habits Chapter 6 naming rules/10th: with <Company>. <Component> namespace name/296123: the Assembly does not have to have the same name as the namespace/296124: consider using the plural/297125 in the namespace: do not use the FCL type name to name your own type. // 297126: Use a noun or a noun group to name the type/298127: use an adjective group to name the interface/299128: consider taking the name of the derived class as the base class name as the suffix/300129: the generic type parameter should be prefixed with T/300130: Name the enumeration type in the plural, and name the enumeration element in the singular number/301131: use PascalCasing to name a public element/302132: consider using a class name as the property name/302133: Use camelCasing to name private fields and local variables/303134: Use a conditional prefix/304135: consider using affirmative phrases to name a Boolean attribute/305136: Prefix A suffix to indicate a new version of an existing type/306137: Delegate and event type should be added with a superior suffix/307138: use verb or adjective phrases for naming events and delegate variables/308139: use a combination of event processor naming/Chapter 4 Code cleanliness/309: use the default access modifier/11th: if you do not know whether to use braces, use/312142: always provide meaningful naming/314143: The method abstraction level should be at the same level/315144: A method only does one thing/316145: avoid too long methods and too long classes/317146: only publish necessary operations/318147: refactor multiple related attributes into one class/319148: do not repeat the code/320149: avoid too long if and switch branches by using the table-driven method/321150: Use the anonymous method and Lambda expression instead of the method/324151: Use the event accessor to replace the public event member variable/325152: minimum, even do not comment/326153: if an exception is thrown, you must comment/326 chapter 12th standardize development behavior/327154: Do not over-design, experience refactoring in agility/327155: submit unit test code with production code/336156: use features to provide multiple versions for the application/342157: perform automated testing starting from the first interface writing/344

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.