xsharp.eu • null-coalescing operator in X#?
Page 1 of 1

null-coalescing operator in X#?

Posted: Thu Apr 04, 2019 9:14 am
by Otto
Two questions:

Is there in X# a null-coalescing operator as in C# the ??

Code: Select all

return source ?? String.Empty;
?

Is in X#

Code: Select all

iif(source==String.Empty,"is empty","is not empty")
the (only) syntax for the C# ternary conditional operator

Code: Select all

source == String.Empty ? "is empty" : "is not empty"
or is there another syntax possible (i'm not looking for the if...then...else...endif construction ofcourse...)

null-coalescing operator in X#?

Posted: Thu Apr 04, 2019 12:33 pm
by Chris
Hi Otto,

For (1), you need to use DEFAULT in X#:

return source DEFAULT String.Empty

For (2), yes, iif() is the equivalent of the ... ? ... : ... syntax. Note that iif() is not a function, it is being handled by the compiler, so it is as efficient as the c# version, just a different syntax.