简体   繁体   中英

Code skipping lines in debugging

I have run into this problem before, many years back, and remember that the usual causes to this type of scenario are due to 1.) Threading or 2.) the program silently failing somewhere due to some exception.

Before posting here I encased the faulty code in a try and catch to see if it was failing but to no avail did not reach the catch block once.

I also scanned the project using CTRL.FIND "Thread" to see if there was any threading the in the project but there was not. Two scenarios ruled out..

I am not completely sure what is causing the below piece of code to skip the if block.

Purpose of the code: To find the nth Prime number and test it using various scenarios

Faulty Piece of Code aka (Implementation.cs) class

 public int FindNthPrimeNumber(int n)
    {

        if (n > 0) //code evaluates condition here but completely skips whats inside the braces
        {
            Debug.WriteLine("Heyyy I got hit!");
        }

        return n;
    }

您的Debug.WriteLine调用可能不会被击中,因为您在Release模式下运行,因此已被优化。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM