Nullable condition operator

Martin6265 via Digitalmars-d digitalmars-d at puremagic.com
Mon Dec 7 03:40:45 PST 2015


Hello,
I think nullable condition operator and null coalescending 
operator should be a nice new features in D.

https://msdn.microsoft.com/library/dn986595.aspx
https://msdn.microsoft.com/library/ms173224.aspx

Same as operator `as`
https://msdn.microsoft.com/library/cscsdfbt.aspx

Why?
Is better to write
(variable as FooBar)?.callMethod();

than
auto var = cast(FooBar)variable;
if (var !is null)
var.callMethod();


or
auto x = (variable as FooBar)?.getRandomNumber() ?? 42;


More information about the Digitalmars-d mailing list