If it is necessary to check string variable on null and "" (empty), then
function String.IsNullOrEmpty can be used:
c0de with operator 'if'
string getName(string name)
{
if (name == null || name == "")
return "default";
else
return name;
}
code with function Sgtring.IsNullOrEmpty()
string getName_with_function_IsNullOrEmpty(string name)
{
if (String.IsNullOrEmpty(name))
return "default";
else
return name;
}
Sample can be download:
http://code.google.com/p/csharp-tips/source/browse/trunk/string_functions/Program.cs
Additional Links:
String..::.IsNullOrEmpty Method
No comments:
Post a Comment