.NET Development - Four simple golden rules

By Anoop Madhusudanan

Vote on HN

1 - Some of us don't use using. Use using where ever possible
using (StreamReader reader=new StreamReader(file)) 
 //your code here 
2 - Forgetting to check if something is null, instead of trying to catch a null condition when an exception occurs
//This might throw an exception
string val=obj.Value.DomeSomething()

//Better, check for null

if (null!=obj.Value)) { 
 // Do your stuff here 
3- Forgetting to check for null after a runtime type cast
   MyType t= x as MyType;
   if (null!=t) { 
      //Do stuff here 
4- Where ever you are allocating something in try block, make sure you've a finally block to release stuff.


  1. Actually i searched for vb.net and asp.net e-book then suddenly i saw your blog i thought it has a more information about them.Its nice blog but i want something like e-books download links.good work
    new york web design

  2. See this for free e-books - http://stackoverflow.com/questions/4705/free-programming-ebooks

  3. Thanks Anoop for your responding but this is online books i need free download e-books link.anyways thanks for it..
    web design new york

  4. Wherever possible there's another way to do null checks, esp inside methods

    if(obj == null) return;

    This does two things,
    1. the line below that, will never be executed, so you are safe.
    2. The braces and indentation reduces drastically and the code that appears last in the method is very readable and maintainable.



Please keep your comments clean.

© 2012. All Rights Reserved. Amazedsaint.com