Use Conditional Breakpoints with Methods Return Value in Visual Studio 2015

Use Conditional Breakpoints with Methods Return Value in Visual Studio 2015

Conditional Breakpoint in Visual Studio is a great way to optimize the debugging time and pause the execution only when the condition satisfied.  Along with the normal condition with in conditional breakpoint in visual studio, we can call a methods from the condition field and based on the return value debugger will stop at the breakpoint.  You have seen this over here – Use Conditional Breakpoints with Method Calling in Visual Studio . This post cover the changes on breakpoint in new Visual Studio 2015

Let’s say you have a method with return type bool and you one of your breakpoint will only hit if IsValidData returns true.

private static bool IsValidData() => true;

If you are wondering about above code block, and how does that work. you must read this new features of C# 6.0 Expression – Bodied Methods in C# 6.0

Now, you have to set the conditional breakpoint from Breakpoint Settings as shown in below,

image

 Must Read : 10 Effective Debugging Tips for .NET Developer

image

Now, during the execution of code, when IsValidData() returns true ( in this case it is true), breakpoint will hit.

image

This will also works for other method returns type, but you need to check with a conditional operator in the breakpoint settings.

Abhijit Jana

Abhijit runs the Daily .NET Tips. He started this site with a vision to have a single knowledge base of .NET tips and tricks and share post that can quickly help any developers . He is a Former Microsoft ASP.NET MVP, CodeProject MVP, Mentor, Speaker, Author, Technology Evangelist and presently working as a .NET Consultant. He blogs at http://abhijitjana.net , you can follow him @AbhijitJana . He is the author of book Kinect for Windows SDK Programming Guide.