Null-Coalescing Operator and Extensions

JN 666total at wp.pl
Sat Aug 25 13:42:30 UTC 2018


On Saturday, 25 August 2018 at 13:33:58 UTC, SG wrote:
> Hi,
>
> 1) I program in C# and I'm wondering if there is something like 
> ?? (Null-Coalescing Operator) in D? (I remember some proposals 
> in the past).
>
>
> 2) Is possible to create Extensions like in C#?
>
> For example:
>
> public int StrToInt (this string s){
>    return int.Parse(s);
> }
>
> var i = "123456".StrToInt();
>
> Thanks.

1) no

2) Yes, through UFCS (Uniform Function Call Syntax). It doesn't 
require any special syntax, for example:

int squared(int i)
{
     return i * i;
}

void main()
{
     writeln(16.squared);
}

will print 256


More information about the Digitalmars-d-learn mailing list