dotnet-daily-tips

030 - Debugger.Break

Today’s topic is courtesy of 🦄 Jarosław Stadnicki 🙏

Do you know that you can put a breakpoint in the code not only by F9 or mouse click but also programmatically👨‍💻?

There’s a System.Diagnostics.Debugger class and Break() method that can be used to trigger a debugger. Probably it’s worth to check if the debugger is actually attached but additionally can be made conditional. Of course sometimes it is worth just break unconditionally.

Read the docs 📑: https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.debugger?view=net-8.0

Did you had a chance to try it out?