jeudi 29 septembre 2016

How does the ternary operator work internally?

I know that

int opening_time = (day == SUNDAY) ? 12 : 9;

is the same as

int opening_time;
if (day == SUNDAY){
    opening_time = 12;
}else{
    opening_time = 9;
}

but what is(written in c#)

if (new Random().NextDouble() >= 0.5 ? true : false)    {
}

the syntax sugar for? I know that the latter code is redundant but it's a question of understanding and i can't figure out in what other form it could be written. Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire