null-coalescing operator in X#?

This forum is meant for questions and discussions about the X# language and tools
Post Reply
User avatar
Posts: 174
Joined: Wed Sep 30, 2015 6:22 pm

null-coalescing operator in X#?

Post 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...)
User avatar
Posts: 4593
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

null-coalescing operator in X#?

Post 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.
Chris Pyrgas

XSharp Development Team test
Post Reply