Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Console/CLI Interpreter?

I wonder if there is something like a standalone Version of Visual Studios "Immediate Window"? Sometimes I just want to test some simple stuff, like "DateTime.Parse("blah")" to see if that works. But everytime i have to create a new console application, put in my code and test it.

The Immediate Window sadly only works when I am debugging something. Could PowerShell do that? Just open a CLI similar to what cmd.exe does, allowing me to execute some C# code?

like image 942
Michael Stum Avatar asked Dec 03 '08 14:12

Michael Stum


3 Answers

Linqpad - I use it like this all the time. http://www.linqpad.net/

Don't be misled by the name - that just describes the original motivation for it, not its functionality.

Just recently he released a version with proper statement completion - that's a chargeable add-on (the core tool is free), but a minute amount of money and well worth it, I think.

like image 170
Will Dean Avatar answered Sep 25 '22 19:09

Will Dean


The Mono project includes an interactive C# shell, this may be just what you're looking for.

http://www.mono-project.com/CsharpRepl

like image 35
James Orr Avatar answered Sep 24 '22 19:09

James Orr


C# Interactive window and csi.exe REPL were added to Visual Studio 2015 Update 1:

Introducing Interactive

The Interactive Window is back! The C# Interactive Window returns in Visual Studio 2015 Update 1 along with a couple other interactive treats:

  • C# Interactive. The C# Interactive window is essentially a read-eval-print-loop (REPL) that allows you to play and explore with .NET technologies while taking advantage of editor features like IntelliSense, syntax-coloring, etc. Learn more about how to use C# Interactive on Channel 9 or by reading our beginner’s walkthrough.

  • csi. If you don’t want to open Visual Studio to play around with C# or run a script file, you can access the interactive engine from the Developer Command Prompt. Type csi /path/myScript.csx to execute a script file or type simply csi to drop inside the command-line REPL.

  • Scripting APIs. The Scripting APIs give you the ability to execute snippets of C# code in a host-created execution environment. You can learn more about how to create your own C# script engine by checking out our code samples.

See What’s New in Visual Studio Update 1 for .NET Managed Languages.

Basically, now you have:

  • IDE REPL — C# Interactive window in VS
  • Script interpreter — csi foo.csx from Dev Cmd Prompt
  • Command line REPL — csi from Dev Cmd Prompt
  • Scripting API
like image 24
Athari Avatar answered Sep 21 '22 19:09

Athari