Saturday, March 31, 2012

Single line if statement

Does anyone have a link to a reference for the syntax to do single line if/else if statements?

Thanks,
DavidIf you're using VB, then you can't do it.

With C#, I'd imagine it's as simple as:

if (a==1) { b=2; } else { b=3 ; }

Two ways in VB:

If condition Then dosomething Else dosomethingelse

Or

IIf(condition, dosomething, dosomethingelse)
I do it sometimes like this

bool isValid = (someObject != null ? someObject.valid : false);

0 comments:

Post a Comment