mercredi 20 juillet 2016

Conditional operator without return value

I have this code:

bool value = false;
if(value)
{
    Console.Write("true");
}
else
{
    Console.Write("false");
}

and I want to shorten it by using the conditional operator but I can't find the correct syntax.

bool value = false;
value ? Console.Write("true") : Console.Write("false"); // does not work

Aucun commentaire:

Enregistrer un commentaire