N/APosted on - 06/14/2012
I want to know about trace class and debug class. Both things are similar to me. WriteIf or WriteLineIf can be done with a simple if statement. Asserting is also confusing. It seems like it could be done by just stepping through the code using breakpoints and the debugger to watch local and auto variables. Can anyone briefly explain how these things work? Thanks in advance.
Idea about trace and debug class in C#
Trace class provides a set of methods and properties which help to trace the execution of the code whereas Debug class provides a set of methods and properties which help to debug the code. Please keep in mind that you can not inherit both the classes.
Though both classes seem to be similar to you, there is a difference between them. You can collect the information about the execution of program in tracing process. Debugging process is used to find and fix the errors in the program.
"If" statement is a basic conditional statement and can not replace WriteIf and WriteLineIf. Both WriteIf and WriteLineIf are used to print the output in a output window.
Example: Debug.WriteIf(true, "True");
In debug compilation, Assert sends a strong message to the programmer. It takes in a boolean condition as a parameter. If the condition is false, it will show a error dialog. It interrupts the normal operation of the program; however it will not terminate the application. If the condition is true, the program will proceed without any interruption.