How to enter debug mode when a condition is met?

Is there a way to enter debug mode when a certain condition is met?

For example, let's say I would like to enter debug mode in the line on which i == 1it becomes true:

using System;

namespace ConditionalDebug
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var r = new Random();
            var i = r.Next(2);
            i += r.Next(2);
            i += r.Next(2);
            i += r.Next(2);
            i += r.Next(2);
            i = 1;
            Console.WriteLine(i);
        }
    }
}

I know that you can set conditional breakpoints such as:

conditional breakpoint

But, of course, I could not use this, since I would have to add a conditional breakpoint for each line in the code where the value of the condition could be changed, and this would be very random in a real application.

So, is there a way to globally set a condition i == 1so that the debugger breaks into a line on which the condition is satisfied?

Thank you for your help!

+5
source share
3

: ""

: " , ". , , , .

  • "" .
  • , .
  • , - ( ) ( ), , / .
  • . , VS Plug-in Macro.
  • - , - , "Break every X Changes".
+3

VS breakpoints , .

?

+1

, , , , , , , - , .:)

+1

All Articles