This syntax regarding null checking baffles me

Imperatorn johan_forsberg_86 at hotmail.com
Mon Jan 11 11:49:02 UTC 2021


On Thursday, 7 January 2021 at 04:57:55 UTC, 12345swordy wrote:
> if (c !is null) Why?????
>
> Would it be simpler to type
>
> if (c is not null)
>
> on a related note. Why are not we allowed to do this?
>
> if (c != null)
>
> when other languages such as c#/java allow for it?
>
> -Alex

One thing you could do is to make an "extension method", exploit 
ufcs and do like c.isNull instead.

Maybe those already exists somewhere.

For reference, in C# we have null-conditional and null-coalescing 
operators. Also, strings for example have string.IsNullOrEmpty 
and IsNullOrWhiteSpace, those are handy.


More information about the Digitalmars-d mailing list