开发者

Inspecting &x in debugger (C#)

Doing this in a console program:

object x = new string(new char[0]);

If one set a breakpoint rigt after x's assignment and bring up the quick watch window, what is the debugger displaying for &x? I was expecting x's address but it looks like I'm wrong?


EDIT: I'm asking this because of another thread, which was pointing out that if one do

object x = new string(new char[0]);
object y = new string(new char[开发者_如何转开发0]);

x and y will reference the same object. As I wanted to check it out, I tried inspecting these variables' addresses in the debugger using the & operator and, at first, I had the impression they were different. But, after expanding the result, second level values do match - so these seem to be "real addresses".


If I display x I get "" with the type reported as "object {string}" - which is what I expect.

&x displays 0x062fd7f0 (in my case) with the type reported as "object&*". Expanding that gives another pointer and the type as "object&".

In the first case the debugger has enough information to work out the type and show you something useful.

In the second case all the debugger "knows" is that the variable is an object so can only display pointers (I think).

UPDATE

Your update makes sense. The value reported by &x and &y are the pointers to the variables. The value they hold is the pointer to the immutable string "".


You cant do this, because memory management is handled by CLR

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜