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?

Interpreter typing in C

I’m developing an interpreter and I have some questions to it. I recently saw a small C interpreter that used a very simple struct like the below for all its objects/values in the language: struct Obj

C Interpreter (Not Compiler)? [duplicate]

Possible Duplicate: Is there an interpreter for C? Is there a C implementation which acts the same as the C abstract machine when executing a C program? That is, a simple interpreter for C as it

Is there an interpreter for C?

I was wondering if there is something like an interpreter for C. That is, in a Linux terminal I can type in python and then code in that interpreter. (I’m not sure interpreter the right word). This

C interpreter written in javascript

Is there any C interpreter written in javascript or java ? I don’t need a full interpreter but I need to be able to do a step by step execution of the program and being able to see the values of varia

C# Interpreter (without compilation)

Is there a ready-to-use C# interpreter out there, that is does not rely on runtime compilation? My requirements are : A scripting engine Must Handle C# syntax Must work on medium-trust environments M

Clang as C++ interpreter?

I’m intrigued by using Clang as embedded C++ interpreter. Is it possible to interpret hello world with it? The aim is to pass source filepath or source code as a string and get input/output streams

C++ interpreter conceptual problem

I’ve built an interpreter in C++ for a language created by me. One main problem in the design was that I had two different types in the language: number and string. So I have to pass around a struct l

Lex Yacc Interpreter in C

I’m writing an interpreter for a programming language in C with Flex and Bison. I have no idea how to generate an AST and I would like to know what kind of performance difference there would be if I j

Python to C converter / interpreter [closed]

What are various tools to convert Python scripts to C. I am mainly looking at speed of such tools/converter/interpreter. Thanks, -J

Python interpreter as a c++ class

I am working on embedding python in to c++. In some peculiar case I require two separate instances of the interpreter in same thread. Can I wrap Python interpreter in to a c++ class and get services f

Answers

Well, this isn’t a direct answer to your question, but you could look at this tool:

Also, if you want to see the IL produced, or similar, there is a tool that plugs into Reflector, called Snippy, based on the Snippy tool that Jon mentions in his own answer further down.

All of these are very nice to use.

If you’re using Mono, there’s this:

CsharpRepl

Don Box hacked something very simple up a few years ago too.

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

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

Along the lines of lassevk’s answer, I’ve got “Snippy”. This was developed for C# in Depth, and the UI is pretty rubbish, but it works – and lets you write extra members (methods, nested classes etc) as well, e.g.

public static void Foo()
{ 
    Console.WriteLine("Hello");
}
...
Foo();

(The … is used to tell Snippy “everything under here belongs in Main”.)

I also find that SharpDevelop is so quick and lightweight that it is the easiest way to whip off a quick test project.

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.

As you suggest, PowerShell can do what you want. For example, to test your DateTime.Parse, the following one liner will do the trick:

PS C:/Documents and Settings/Dan> [System.DateTime]::Parse(“Blah”)
Exception calling “Parse” with “1” argument(s): “The string was not recognized as a valid DateTime. There is a unknown word starting at index 0.” At line:1 char:25 + [System.DateTime]::Parse( <<<< “Blah”)

PS C:/Documents and Settings/Dan> [System.DateTime]::Parse(“1/2/3”)

01 February 2003 00:00:00

Note that the above uses the current release of PowerShell (v1.0). The next version of PowerShell will allows you to intermingle C# with PowerShell scripts more directly. To whet your appetite, watch this 7 minute screencast “C# to PowerShell” by Doug Finke. Very impressive!

You may find the Object Test Bench useful. It’s not very well known, but lets you create instances of classes, execute static methods and so on. It can be useful for discovering how to use unfamiliar APIs or for quick debugging of your own classes and methods, saving the creation of a test harness for simple checks.

You can find the MSDN documentation here:

http://msdn.microsoft.com/en-us/library/c3775d98%28VS.80%29.aspx

If you could wait a while.. it looks like there could be a C# equivalent of Ruby’s irb in time for C# 4.0 Anders H. demonstrated an interactive console session where you could type in arbitrary C# code and see results in his ‘Future of C#‘ piece at PDC 2008. You could even pop a WPF Window from it and then play with it via the console interface. Pretty cool.

Use LINQPad.

Name notwithstanding, it can execute any C# or VB code, from simple expressions to entire classes.

Plus, it can visualize entire object graphs in the results.

You can even add references to your own assemblies.

If you happen to know and like Python, then IronPython may be a good alternative. It comes with a (Python) REPL console (ipy.exe) where you can import and use all of the .Net types.

I find it useful for testing out little things, exactly like DateTime.Parse(“Blah”).

Note that it can’t actually execute C# code, but if all you want is access to .Net, then it’s perfect. Also, if you install the IronPython Tools for VS, you can start a REPL session right in VS using a single keyboard shortcut (Alt+I) and leave it running in a docked window for when you need it.

Try the C# REPL Script Environment that is part of the O2 Platform. It is exactly what you are asking for.

It will give you a perfect environment to try out all C# features and APIs (conceptually the O2 REPL environment is similar to LinqPAD)

You should also take a look at Roslyn from Microsoft. On Multiple Roslyn based tools (all running Stand-Alone outside VisualStudio) , the first one is a simple Roslyn REPL

We’ve just released CShell a full featured C# REPL IDE. It supports code completion, script files, adding references and is really extensible. Also we plan to add NuGet support soon, which will make it super quick to write some code and see how it works.

http://cshell.net/

C# Console/CLI Interpreter?

We love LINQPad but it doesn’t have a REPL, the code is executed once and you cannot do anything further with the results unless you modify the script and run the whole script again. This is okey, but sometimes if you want even more a scripty feeling then to evalute your code in a REPL is really nice and convenient.

Try scriptcs, it’s not integrated into the VS IDE but it does let you type and run C# in a script window without the need for a project compiler etc…

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 2015 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

Update: http://avillenas.com/post/interactive-c

Well, you can try this.

  1. Download and install dotnet.github.io
  2. Open cmd
  3. Type “dotnet repl”
  4. Type whatever you need.

I did what you wanted to do. Click here to see the gif

The Roslyn project sources contain a REPL called CSI (http://source.roslyn.io/#csi/Csi.cs). The Csi class is currently internal but with the the “csi” project (Roslyn.sln: Interactive/Hosts/csi) an executable console application is available that supports e. g. the command #r to load an assembly and #load to load and execute script files (start the csi and use #help).