65.9K
CodeProject is changing. Read more.
Home

Best practices in developing ASP.NET applications

starIconstarIconstarIconstarIconstarIcon

5.00/5 (4 votes)

Jan 31, 2011

CPOL
viewsIcon

9450

Initializing is great... unless you have no control over the contents.Consider this:String strTmp = String.Empty;strTmp = SomeRandomMethod();//Suppose SomeRandomMethod returns null under some circumstances...Now anything you try to do with strTmp (other than compare to null) will...

Initializing is great... unless you have no control over the contents. Consider this:
String strTmp = String.Empty;
strTmp = SomeRandomMethod();
//Suppose SomeRandomMethod returns null under some circumstances...
Now anything you try to do with strTmp (other than compare to null) will cause an exception - inlcuding the original tip:
if (strTmp.Length == 0) {
//etc
}