Geeks With Blogs
Ramesh Blog .NET Dash

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.

Posted on Friday, November 7, 2003 10:29 AM | Back to top

Comments on this post: Some clean code...

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Ramesh Arimilli | Powered by: