views:

94

answers:

3

I am a newbie learning C# after C++. VS2010.

Trying to debug my code, I come across weird empty lines in the "locals" frame. The debugger just quits after a few seconds of me staring at these empty lines.

Please check it out: http://pastebin.com/KZbfy8JF

Thanks.

I've spent at least 3 hours looking for solutions and playing around with code to no avail.

A: 

Ok generally, stack overflow would mean that you're recursing without going back. I don't see however where you do that. What I'd do would be to insert a Console.WriteLine statement in a few strategic places to see which lines are executed and how often. For example, on the beginning of Insert, and in the inner loop. This should give you (and us ;) a bit more information.

Nicolas78
+8  A: 

The Value property getter and setters are infinitely recursive - change them to this:

public T Value { get; set; }
Lee
+1 this is the answer. It's an easy mistake to make if you're not careful.
George Stocker
I hate that the compiler doesn't find these...
Brian Rudolph
THIS IS IT!!!! Thank you so much!!! I can go on to debug the rest of my buggy code =)
CatZilla
+1  A: 

Already answered (Value get/set) but here is a tip:

In VS.NET, press CTRL+ALT+E to open the Exceptions dialog (depending on your profile selected in VS.NET, it may be under Debug->Exceptions as well). This lets you break when certain exception types are thrown, as opposed to the full stack unwinding and the program ultimately crashing.

For "Common Language Runtime Exceptions" check the "Thrown" checkbox, hit OK, then run your program. The execution of your program will stop at the point of exception, which should make it much more obvious.

In your case, the program breaks on your property. To see more, open the Call Stack wndow (Debug->Windows->Call Stack or CTRL+ALT+C) to see the full stack and you'll see your property is just about the only thing in it.

Adam Sills