0

i want to test if statements directly, my problem is it's waiting so many long to test my if statements in my code. this is my code :

    byte isFive = _checkReadLengthIsFive;

    if (readLength == 5)
    {
        isFive++;
        _checkReadLengthIsFive = isFive;
        if (isFive == 2)
        {
           string appendText = "WRITE FAIL" + Environment.NewLine;
           File.AppendAllText(Fullpath, appendText);
           DisplayData(MessageType.Incoming, "DAPAT!" + "\n");
        }
    }

to reach in this if statement, i waiting so long because readLength = 5 is rarely happening. Is it possible to use immediate window? if possible please tell me how? thanks for helping and responses.

yosafat
  • 243
  • 1
  • 4
  • 17

2 Answers2

1

Yes you can change a variable's value in the immediate window while your code is running (debugging). You should be able to set the variable's value by using the window and typing something like readLength = 5;. You are also able to hover the mouse over the variable and click on the value and type in a new value.

Brendan L
  • 1,436
  • 14
  • 13
  • what must i type in immediate window? i see only blank sir – yosafat Sep 28 '16 at 02:17
  • By the way, the immediate window and watch window are only useful when your program has hit a breakpoint. Put a breakpoint on your line 'if(readLength == 5), when that breakpoint is hit type 'readLength = 6' into the immediate window. Here is a short but handy tutorial on the immediate window to get you started: http://www.blackwasp.co.uk/VSImmediate.aspx – Brendan L Sep 28 '16 at 02:23
  • this if is rarely happen sir, when we waiting breakpoint hit if(readLength==5), it's waste time too long because that if rarely happens – yosafat Sep 28 '16 at 02:32
0

If you want to test your code inside if statement, just change the code from

if (readLength == 5)

to

if (true)

After everything is ok, you change back to if (readLength == 5)

  • change in immediate window or where ? – yosafat Sep 28 '16 at 02:11
  • I think no need to use immediate window. As you say you need to wait so long to make the if statement happens, my idea is why don't modify the code to make the if statement happen, then test the code inside if statement. – Huu Thien Tan Nguyen Sep 28 '16 at 02:13
  • oh so if we want to test the code only with if(true) – yosafat Sep 28 '16 at 02:15
  • why be like that? sorry i am really new in c# . could you explain it more detail? – yosafat Sep 28 '16 at 02:16
  • AS I understand, you want to test if statements directly, and your problem is it's waiting so many long to test your if statements in your code, so change the code to if (true) so that it can always happen then you no need to wait so long to test your code. – Huu Thien Tan Nguyen Sep 28 '16 at 02:19
  • this is already i try and this is what i need! big thanks for you. @Huu Thien Tan Nguyen – yosafat Sep 29 '16 at 08:50