Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Immediate Window in Design Mode

According to Microsoft: "The Immediate window is used at design time to debug and evaluate expressions, execute statements, print variable values, and so forth."

Notice it says "at design time". I have read other statements on the web to this effect as well.

However, when anybody asks why they get the "The expression cannot be evaluated while in design mode." error, everybody always states that it only works in debug mode.

I can understand some things will not work in design mode when they reference items like textbox box values. But I really don't understand why I have to set a breakpoint, run my application, and wait for it to get to the breakpoint, just to find out what 1 + 1 is.

I admit to frustration as I'm coming from Visual Basic 6.0. There I can print 1 + 1 and get 2 while in design mode. I can also call public functions and get answers while in design mode.

All of this comes from my looking for answers to type converting. Since I couldn't find an answer on the web, I decided the quickest and easiest way was to just test some statements REAL QUICK in the immediate window to see which one worked.

Is .NET a step backwards when using the immediate window?

like image 214
Tom Collins Avatar asked Apr 18 '12 18:04

Tom Collins


1 Answers

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

It's very different from Immediate Window since REPL loop can be somewhat isolated, but it seems like that you can even interact with your project to some extent: Can the C# interactive window interact with my code?

This dates back even to 2011-2012, and it's default part of Visual Studio 2015 CTP1 since the end of 2015: View -> Other Windows -> C# Interactive

like image 170
Csaba Toth Avatar answered Sep 26 '22 15:09

Csaba Toth