.NET Best Practices


The attached white paper disucsses the following topics in terms of best practices in .NET and C#.

1.       Managed Heap and Garbage Collection Overview           

a.       Memory Allocation        

b.      De-allocation of Memory            

c.       Object Finalization          

d.      Generations in GC          

2.       Minimize Boxing and Unboxing

3.       Finalize() Method Implementation         

4.       Implement the Standard Dispose Pattern            

5.       Utilize using and TRy/finally for Resource Cleanup           

6.       Always Use Properties Instead of Accessible Data Members      

7.       Prefer readonly to const              

8.       Prefer the is or as Operators to Casts     

9.       Always Provide ToString()           

10.   Ensure that 0 is a valid State for Value Types      

11.   Consider overriding the Equals() method for value types             

12.   Understand the Relationships Among ReferenceEquals(), static Equals(), instance Equals(), and operator==       

13.   Avoid pre-allocating memory    

14.   Prefer Variable Initializers to Assignment Statements    

15.   Initialize Static Class Members with Static Constructors 

16.   Utilize Constructor Chaining       

17.   Prefer Small, Simple Functions  

18.   Avoid inefficient string operations          

19.   Prefer Single Large Assemblies Rather Than Multiple Smaller Assemblies             

20.   Locking and Synchronization guidelines

21.   Minimize Thread Creation           

22.   Do not set local variables to null.              

23.   Miscellaneous  

a.       Multithreading 

b.      erialization         

c.       Remoting           

d.      Security               

 


Similar Articles