I've been working in C# and VB.NET a lot lately, and the other night I noticed this strange behavior when running some through a debugger and trying to look at the contents of a Dictionary object. I'm fairly certain I've looked through a Dictionary in C# before and saw its contents, but now what I'm seeing is:
Poking around in those sub parts, like the keys and values, doesn't show what's in the dictionary, just take me around in a loop to this same debugger window. I can't look at my values anywhere here.
Where as VB.NET looks fine:
Any idea why C# is different? Is there a setting or something I have off?
Run and Debug view# To bring up the Run and Debug view, select the Run and Debug icon in the Activity Bar on the side of VS Code. You can also use the keyboard shortcut Ctrl+Shift+D.
To see if a key exists in a Dictionary, we should use ContainsKey or TryGetValue. If we just access the key directly, we might get a KeyNotFoundException. Note We can use exception handling to detect the KeyNotFoundException, but this will be slower than not causing an exception. Unhandled Exception: System.
Yes, Visual Studio allows the developer to modify the value of a variable during debugging in a c# application. Set a breakpoint, hover the mouse above the variable so that a tooltip appears with the name of the variable and the variable's current value.
Can you change the value of a variable while debugging a C# application? Yes, if you are debugging via Visual Studio.NET, just go to Immediate window.
Somehow you're being shown the "Raw View -> Non-Public members" window. However, the list of numerically-indexed values should be accessible if you scroll down in this window to the next-to-last row, "values". Can you post a screenshot showing the expanded "keys" window?
Uncheck Tools -> Options -> Debugging -> General, 4th option from last: "Show raw structure of objects in variable windows". (Thanks should also go to https://stackoverflow.com/a/13422426/2236012 for sharing this settings path.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With