Let’s say you want the value of a
string called
strCurrentName to be set the same as the value of another
string called
strPreviousName, but you know that there’s a chance that
strPreviousName could be
null and if it is you simply want to give
strPreviousName a valued of
“No Name Entered”.
What you would do is this
C#:
/*
Here we'd prefer to use strCustomerName, but there's a chance it may be null SO...
if strCustomerName is null, then strCurrentName gets "Name Unknown" instead.
*/
string strCurrentName = strCustomerName ?? "Name Unknown";
No Comments