On Friday, 4 April 2014 at 19:56:14 UTC, Jesse Phillips wrote:
On Friday, 4 April 2014 at 15:13:25 UTC, Bienlein wrote:
What I was actually looking for was how to get this to work:

immutable int b = if(1 == 1) { return 123; } else { return 456; };

But I'm happy enough with the solution through a delegate.

What bearophile said, or:

immutable int b = {if(1 == 1) { return 123; } else { return 456; }}();

Thanks, that's it! Now I can also do what I initialliy wanted to (e.g. have several lines of code in the expression blocks):

immutable int b = {
    if(1 == 1) {
        writeln("123");
        return 123;
    } else {
        writeln("456");
        return 456;
    }
}();

Reply via email to