Blog Stats
  • Posts - 36
  • Articles - 0
  • Comments - 11
  • Trackbacks - 23

 

Some clean code...

Simple tip that's saved me some time:

//This will set the variable test to null:

string test = Convert.ToString(ConfigurationSettings.AppSettings["Missing.Value"]);

//This will throw an exception:
string test = ConfigurationSettings.AppSettings["Missing.Value"].ToString();





The problem with the second statement is that null doesn't have a .ToString() method.
Either situation can be handled, but most of the time it's a lot cleaner to check for a null than to raise the exception.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Feedback

No comments posted yet.


Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

 

 

Copyright © Ramesh Arimilli