Guess the output of the following program:- class SomeClass : IDisposable { public SomeClass() { Trace.WriteLine("SomeClass - Attempting instance creation"); throw new Exception("Ohh !!! Not Now"); } public void Dispose() { Trace.WriteLine("SomeClass::Dispose"); } ~SomeClass() { Trace.WriteLine("SomeClass::Finalizer"); } } int Main(string args[]){ try{ SomeClass sc = new SomeClass(); }catch(Exception ex){ Trace.WriteLine("Main - {0}", ex.Message); } } This will be the output of the program:- SomeClass - Attempting instance creation Ohh !!! Not Now SomeClass::Finalizer If you are surprised with the last line of the output, that will be the intent of our discussion. In the .NET [managed] world, the garbage collector is entirely responsible for memory management - allocation and deallocation. In C#, an instance of a class is created using the new keyword. When an instance creation is req...
Another effective [debugging] technique is to explain your code to someone else. This will often cause you to explain the bug to yourself. Sometimes it takes no more than a few sentences, followed by an embarrassed "Never mind. I see what's wrong. Sorry to bother you." This works remarkbly well; you can even use non-programmers as listeners. - From "The Practice of Programming" by Brian W Kernighan & Rob Pike.