Why can't I declare new variables in the immediate window?
Just answering the question from the headline:
In VS2015 you can declare variables in the immediate window. But you have to end your command with a semicolon:
var abc = "abcdef";
Expression has been evaluated and has no value
or
var n = 7;
Expression has been evaluated and has no value
or
int o = 8;
Expression has been evaluated and has no value
To show the result, just type the name of your variable:
abc
"abcdef"
or
?abc
"abcdef"
or
?abc;
"abcdef"
or
abc;
"abcdef"
Do not use Dim
jack = 12
? jack
12 {Integer}
With C# you can declare variables in the immediate Window during debugging (I honestly don't know if it is a VS2008 feature only, but I have just verified it in VS2008 team edition).
You can't declare variable in the Watch window (in fact the error message says "Declaration statements are only allowed in the immediate window") but you may watch any variables you have created in the immediate window.
Also, you can't use var
when declaring variables in the immediate window, but apart from that you can do what you're asking.