Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

306
Views
Are parameters of conditional methods (Debug.Assert(...)) optimized away in release mode?

I often have expensive linq queries embedded in Debug.Assert().

Ex: Debug.Assert(!orderShipmentStatusLogs.GroupBy(c => new { c.Id, c.StartDateTime }).Any(c => c.Count() > 1));

In this case orderShipmentStatusLogs can be a huge list - so this code may be slow.

For performance i'm asking myself whether that's smart or not, i know the Debug.Assert() method gets removed in release mode, but from reading the docs:

Any arguments passed to the method or attribute are still type-checked by the compiler. https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.conditionalattribute?view=net-6.0

I'm a bit doubtfull.

So am I safe here or am i accidently slowing my app down by adding in heavy assertions? Is the parameter to Debug.Assert() optimized away?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The entire Debug.Assert line is optimised away when you build in Release mode. So:

Console.WriteLine("Before");
Debug.Assert(false);
Console.WriteLine("After");

Becomes:

Console.WriteLine("Before");
Console.WriteLine("After");

You can see this using SharpLab. In Debug mode the Assert is still there but in Release it is gone.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!