Point struct refuses to be created
This should be simple enough. Here's my one line of code that's giving me trouble:
Point tp3 = new Point(0.0, 0.0);
And yet if I break directly after that 开发者_JAVA技巧and type "tp3" into the Immediate window, I get "The name 'tp3' does not exist in the current context." What the heck is going on? I have much more code in this project than just that one line, but I'm not sure what could be affecting it. I'm literally breaking on the line directly after this one, and tp3 is nowhere to be seen. If I hover over tp3 while in break mode, I get nothing there either.
Does anyone know what could be causing this? Why isn't C# letting me creating a Point??
Edit: I am using the System.Windows.Point struct, and I discovered that I was actually running in Release mode when I meant to be in Debug. Which, of course, was the issue, since tp3 was being garbage collected. Thanks everyone for the quick and accurate responses! I was about to pull my brains out. Yes, my brains.
Edit #2: Actually, as Maupertuis pointed out (pun completely intended), since Point is a struct it isn't be garbaged collected, instead the compiler isn't even allocating space for it in the first place since it isn't used. Thanks Maupertuis!
If tp3 is no longer used it will be classed as Out Of Scope and subject to Garbage Collection.
Try adding something like Point tempP = tp3;
after your line, you should be able to see it then.
If the Optimize Code checkbox is checked in the project properties, it will essentially set a local object to null after its last use so that it can be garbage collected. Also, if the variable is not used anywhere, it will not actually be allocated.
Doesn't directly depend on the Debug or Release mode, but Debug mode defaults to unchecked (not optimized) and Release defaults to checked.
You are passing floating point arguments to an integer constructor.
Try instancing a PointF instead:
PointF tp3 = new PointF(0.0f, 0.0f);
Even better, since PointF is a structure just use:
PointF tp3 = PointF.Empty;
精彩评论