D
D
Dmitry Gavrilenko2016-01-25 16:43:52
Computer networks
Dmitry Gavrilenko, 2016-01-25 16:43:52

How to track the conditions (OR) under which the entry into the block occurs?

string str = "string";
      int num = 3;
      ConsoleColor color = ConsoleColor.DarkRed;
      
      if(String.Equals(str, "string2") || num.Equals(3) || color.Equals(ConsoleColor.DarkRed))
      {
        //TODO
      }

Hello. "What the hell did he write?" you ask. There were a lot of situations when it was necessary to track under what conditions the TODO block began to be executed. Create own if() blocks for each check? - you get a repeating code. In this particular condition, the input is due to num.Equals(3) and color.Equals(ConsoleColor.DarkRed). So, how to determine what caused the entry? Are there any special instructions?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
alexxandr, 2016-01-25
@alexxandr

do this:

cond_num = 0 ;
if (/*condition1*/) {cond_num =1;}
else if (/*condition2*/) {cond_num =2;}
else if (/*condition3*/) {cond_num =3;}
if (cond_num > 0)
{
printf("Condition %d passed/n", cond_num);
//TODO
}
}

A
Armenian Radio, 2016-01-25
@gbg

Create separate blocks. Take out the repeating code in procedures.

D
Dmitry Kovalsky, 2016-01-25
@dmitryKovalskiy

And you write a small logging function that returns true and add something like "num.Equals(3) && WriteLog("num.Equals")" to each check. Accordingly, you will find out in the logs due to what condition you failed there. Although performance will drop due to such nonsense.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question