1

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?

Community
  • 1
  • 1
HericDenis
  • 1,364
  • 12
  • 28

3 Answers3

2

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.

Jason Malinowski
  • 18,148
  • 1
  • 38
  • 55
1

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.

   });
Hogan
  • 69,564
  • 10
  • 76
  • 117
  • Ok, this should work in Immediate window in my silly example. But what if I want to do something more complex that does not fit in a single expression? i.e. when I have to implicitly write a for loop? – HericDenis Jul 05 '13 at 00:01
  • You would never *have to* write a for loop -- linq can do anything. – Hogan Jul 05 '13 at 00:02
  • Wow, I'm sorry, I'm not familiar with that. So, without linq, using common multiline code, there is no option? – HericDenis Jul 05 '13 at 00:07
  • 3
    Unfortunately, lambda expressions are not supported (yet!) in the Immediate Window. – fcuesta Jul 05 '13 at 00:11
  • Well, no lambda expressions at Immediate Window. None of that works. – HericDenis Jul 05 '13 at 01:38
  • I tried to create a static method through C# Interactive and then use it into Immediate Window, thought it was not going to work and it doesn't. The method's context is only the C# Interactive window (I think). – HericDenis Jul 05 '13 at 01:47
  • 1
    You could also simply add the code for the thing you want to try - well, at least if you know in advance. Still, you could make it flexible in several ways, like at least parameterizable. Then call it from immediate. – Andreas Reiff Jul 05 '13 at 05:04
0

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.

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179