Programmatically adding break-point in Visual Studio

Many a times, we wish to debug our code based on some condition, we can do this by using code statements in Visual Studio.
There is no need to keep a break-point explicitly, we can use the "Break" method present in `System.Diagnostics.Debugger` class. Here is a short example with console application, but we can do the same for all types of projects built with .Net framework.
  1. static void Main(string[] args)
  2. {
  3. Console.WriteLine(2);
  4. int x = 10;
  5. Console.WriteLine(x);
  6. if (x == 10)
  7. System.Diagnostics.Debugger.Break();
  8. Console.WriteLine(1);
  9. }
 Here, when we run the application in Debug mode, breakpoint will automatically hit the line# 7. Thus, this will be helpful when we wish to debug only when some condition is satisfied.