Direct window in design mode

According to Microsoft: "The" Direct "window is used during development to debug and evaluate expressions, execute statements, print variable values, etc."

Please note that he says "during development". I also read other statements on the Internet about this.

However, when someone asks why they get “expression cannot be evaluated in design mode”. error, everyone always claims that he works only in debug mode.

I understand that some things will not work in design mode when they refer to elements such as text field values. But I really don’t understand why I need to set a breakpoint, start my application and wait for it to get to the breakpoint to find out what 1 + 1 .

I admit disappointment as I come from Visual Basic 6.0. There I can type 1 + 1 and get 2 in development mode. I can also call public functions and get answers in development mode.

All this comes from my search for type conversion answers. Since I could not find the answer on the Internet, I decided that the quickest and easiest way was to simply check some REAL QUICK statements in the immediate window to see which one worked.

Is .NET a step backward when using the direct window?

+7
source share
3 answers

I understand your disappointment. Fortunately, the development of Roslyn (Microsoft's open source C # compiler) allowed for the so-called "interactive Windows" in Visual Studio. You need to install Roslyn, and after a few simple setup steps, you can evaluate the C # expressions in this window: https://github.com/dotnet/roslyn/wiki/Interactive-Window

This is very different from Immediate Window, because the REPL loop may be somewhat isolated, but it seems that you can even interact with your project to some extent: Can a C # interactive window interact with my code?

This applies even to 2011-2012, and by default this part of Visual Studio 2015 CTP1 is from the end of 2015: View -> Other Windows -> C# Interactive

+3
source

In short, it depends on the context of your application, that is, what solution you chose in the solution explorer and its type of project. for example Web Projects, will not evaluate instant expressions during development because it needs to configure this environment, however libraries and projects like the console will.

MSDN Status:

"When creating a context for evaluating a development-time expression, Visual Studio refers to the currently selected project in the Explorer solution. If no project is selected in the solution explorer, Visual Studio tries to evaluate the function against the launch project. If the function cannot be evaluated in the current context, you will get an error message. If you are trying to evaluate a function in a project that is not a launch project for the solution, and you get an error message, try selecting the project in Solution Explorer and try again. "

However, if you are in a web project, you will need to click a breakpoint to evaluate the expressions in the Immediate window.

This may be considered in other answers.

+1
source

For me, I can do what you mentioned in the immediate window of Visual Studio 2008, for example, find out the sum of 1 + 1 or find out the length of "sdfd". Length etc. Can be done from a direct window. So this is not a step backward in .NET.

0
source

All Articles