C#, fast assignment

C#, fast assignment

Here is a short way to declare a variable and set a value according to a condition:

bool var = (something == true) ? true : false;

The long way would be:

bool var;
if (something == true)
{
    var = true;
}
else
{
    var = false;
}

I like the short way. You have to decide for yourself

Update:

This was a bad example. If you want to set a bool, just type:

bool var = something;

Leave a Reply