Hi,
Jeff wrote:
Hey
I've bought the book "ASP.NET 2.0 website programming, Problem, Design,
Solution" and some of its code examples is this code:
protected static string ConvertNullToEmptyString(string input)
{
return (input == null ? "" : input);
}
I have problem understanding this line: (input == null? "":input);
input shall only be set to "" if the value of input is NULL, but I don't see
any if-statement in this code. ?
Best Regards!
Jeff
The '?' conditional statement evaluates the first term (after the '?'
and before the ':') if the condition is true, and evaluates the second
term (after the ':') if the condition is false.
In that case, the code ensures that the "null" value is never returned,
but only an empty string. Translated to an "if" expression, it would be:
if ( input == null )
{
return "";
}
else
{
return input;
}
HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering:
http://www.galasoft-LB.ch
PhotoAlbum:
http://www.galasoft-LB.ch/pictures
Support children in Calcutta:
http://www.calcutta-espoir.ch