mardi 25 septembre 2018

Refactor if condition so that if and else block's logic gets interchanged. c#

In my windows application , I have something as below.

bool somebooleanValue = getBooleanValue();
string someString = getStringValue();

if (!somebooleanValue && someString == "StringValue")
{
    //do nothing
}
else
{
    // do some calculations
}

Here , if the somebooleanValue is false and someString is equal to "StringValue" , it has to skip the calculations that are to be done. So for that i have put a condition like above.

Now if I have to refactor the code and change the condition , so that if block is not blank , how should I do that?

I have tried this

if !(!somebooleanValue && someString == "StringValue")
{
    //do some calculations
}
else
{
    // do nothing
}

But it is giving an error saying ") expected". I'm not able to figure out what is wrong. Can anyone help me please

Aucun commentaire:

Enregistrer un commentaire