Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The title of the question pretty much says it all: in Visual Studio 2019, how do I set a conditional breakpoint that calls Math.Abs()?

Eg. Math.Abs( x ) > 0

What I have tried:

I have tried prefixing the call, like this: System.Math.Abs( x ) > 0

I've also tried searching for an answer but came up blank. Oddly, I could find how to call a C++ stdlib function (like strcmp) but nothing for C#.
Posted
Updated 2-Aug-20 22:14pm

Does this help: Use breakpoints in the debugger - Visual Studio | Microsoft Docs[^] - it has a section on conditional breakpoints.

I tried it with a BP on the Console line:
for (int i = 0; i < 100; i++)
    {
    Console.WriteLine(i);
    }
I set a BP, then right clicked and selected "Conditions..."
Leaving "Conditional Expression", and "is true", in the expression box I typed "Math.Abs(i) == 5" and closed.
The breakpoint triggered only on the sixth iteration.
 
Share this answer
 
v3
Comments
Patrick Skelton 3-Aug-20 4:39am    
Mmm... that's strange. It does indeed work fine now. I guess I must have had a syntax error or something. I'll leave the question up because it may provide a nice quick answer for anyone else who may come along. Thank you.
OriginalGriff 3-Aug-20 4:49am    
You're welcome!

It failed for me the first time as well - I used the English spelling of "Maths" instead of the American "Math" :blush:
You cannot debug the predefined methods.The other ways to see the output values is by using quickwatch or assign to variable and check the condition.
 
Share this answer
 
Comments
OriginalGriff 3-Aug-20 4:22am    
Um ... are you sure? Conditional breakpoints using "internal functions" works fine for me ...
Member 14885087 3-Aug-20 4:50am    
I have tried this and works for me
int testInit = 1;
for (int i = 0; i < 100; i++)
{
if(Math.Abs(i)> 3)
{
Console.WriteLine("Test");
}
Console.WriteLine(i);
}
I put conditional break point for Math.Abs(i)> 3 with conditional expression 'i==5' and the bp has worked for me
OriginalGriff 3-Aug-20 4:25am    
Oh, and just in case you misunderstood the original question - you can debug into "predefined methods" including framework library ones quite easily (and it can be very handy):
https://docs.microsoft.com/en-us/visualstudio/debugger/how-to-debug-dotnet-framework-source?view=vs-2019

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900