Habib is right -- because string
is a reference type.
But more importantly, you don't have to check for null
each time you use it. You probably should throw a ArgumentNullException
if someone passes your function a null
reference, though.
Here's the thing -- the framework would throw a NullReferenceException
for you anyway if you tried to call .ToUpper()
on a string. Remember that this case still can happen even if you test your arguments for null
since any property or method on the objects passed to your function as parameters may evaluate to null
.
That being said, checking for empty strings or nulls is a common thing to do, so they provide String.IsNullOrEmpty()
and String.IsNullOrWhiteSpace()
for just this purpose.