Passing null parameters to String.Format is safe

I wanted to use String.Format with parameters that can be null. Firstly i decided to put some conditional code like
if(arg1!=null) but then desided to check, if it is handled automatically. And from Reflector it looks that it handles nulls

if (str2 == null)
    {
        str2 = string.Empty;
    }
So it safe to write code like 

String.Format("({0}{1})", a1,a2 ) ,

even if some parameters are null.

posted @ Wednesday, January 09, 2008 3:54 PM

Print

Comments on this entry:

No comments posted yet.

Your comment:



 (will not be displayed)


 
 
 
Please add 7 and 5 and type the answer here:
 

Live Comment Preview:

 
«October»
SunMonTueWedThuFriSat
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678