简体   繁体   中英

Can I interact with the current debugging session variables using C# Interactive window or Immediate window?

As I saw here , I'm able to use both of this windows to create objects and use methods from my own code. But while debugging (paused or breakpoint-stopped) I was able to access the positions of an array at the current context through the Immediate window, like this: If I have a debugging session paused right after this code:

    byte[] R = new byte[100];
    for (int i = 0; i < 100; i++)
    {
        R[i] = (byte)1;
    }

I am able to access, say, R[37] through Immediate window and see it's value, but I'm not able to code a loop in Immediate window to verify if all values are equal (just a silly example), actually, I'm not able to code at all at this (as this is not it's purpose).

From the other side, I am able to code in C# Interactive, but cannot interact with the current debugging session variables.

Well, I'm afraid that the answer is negative, but is there any way to archive this (code with current debugging session variables) in VS2012?

You could use linq to do anything you can do in a loop because it is evaluated as an expression

for example

  R.Where(item => item != R[0]);

Will show you all items not equal to the first item.


Here is why you can do anything with a linq expression:

Enumerable.Range(1,1).Select(one => {

     // any function code you want here
     //return any type of variable.

   });

As you expected, the answer is no, there's no way to interact with your debugee's state from the Interactive Window. This is a scenario we continue to think about, but until then you're stuck with the Interactive Window, with all it's limitations.

One approach is to add static helper methods to your code to assist in such investigations.

If you can't modify code - LINQ does provide a lot of useful methods as pointer by Hogan, also due to restriction on "no lambda expressions in immediate window" you are limited to relatively basic call.

Also look at String.Join that takes an IEnumerable - useful to combine values to display (if ToString on elements makes sense.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM