Why You Need to Use System.Diagnostics.Debug More Than You Do
page 2 of 4
by Tim Rayburn
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 42455/ 133

About System.Diagnostics.Debug

There is one very important thing you need to know about this object and all its methods: You are writing code in invisible ink!  Now I am sure you are going, "that's it, Rayburn has finally gone off the deep end." But hear me out!  Consider Listing 1.

Listing 1 - A simple System.Diagnostics.Debug call

class Program
{
  static void Main(string[] args)
  {
    Debug.Assert(true"Vanishing code!");
  }
}

Simple enough yes?  Well, let us compile this in Debug mode and see what Lutz's Reflector has to say about it.

Listing 2 - Reflector disassembly of Debug mode compile

image 

Yep, just what you would expect.  I am sure now you are totally convinced I have lost it.  But watch, swap this to Release mode and…

Listing 3 - Reflector disassembly of Release mode compile

image

instantly vanishing code!  So the key here is that you can use the Debug object, and all its methods, with reckless abandon and, when you actually compile a release build, all of it goes away.


View Entire Article

User Comments

No comments posted yet.






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2014 ASPAlliance.com  |  Page Processed at 10/2/2014 6:25:11 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search