2

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?

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Well, this is it I think. Not helpful at all but the right answer.
@embert: sadly, no.
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.

   });

7 Comments

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?
You would never have to write a for loop -- linq can do anything.
Wow, I'm sorry, I'm not familiar with that. So, without linq, using common multiline code, there is no option?
Unfortunately, lambda expressions are not supported (yet!) in the Immediate Window.
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.
|
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.