Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do Debug.WriteLine() argument expression evaluation side effects happen in release builds?

According to the accepted answer on this question:

When the application is compiled in the release configuration, 
the Debug elements will not be compiled into the code.

Do the argument expression evaluation side effects of Debug.WriteLine() (and similar) happen in release builds? I'm not sure what "Debug elements" really means.

like image 792
Mike Avatar asked Jun 24 '16 16:06

Mike


1 Answers

This is easy enough to try yourself:

class Program
{
    static void Main(string[] args) {
        int i = 0;
        Debug.WriteLine(i++);
        Console.WriteLine(i);
        Console.ReadLine();
    }
}

In Debug Mode the console prints 1. In Release Mode the console prints 0.

like image 170
helrich Avatar answered Oct 20 '22 00:10

helrich