40

During the last 10 minutes of Ander's talk The Future of C# he demonstrates a really cool C# Read-Eval-Print loop which would be a tremendous help in learning the language.

Several .NET4 related downloads are already available: Visual Studio 2010 and .NET Framework 4.0 CTP, Visual Studio 2010 and .NET Framework 4 Training Kit. Do you know what happened to this REPL? Is it somewhere hidden among examples?

I know about mono repl. Please, no alternative solutions.

George
  • 15,241
  • 22
  • 66
  • 83
  • 11
    I know this is super old, but for the next person that stumbles across this as I did looking for a C# Roslyn REPL (basically the one Anders is using) go to: [http://www.microsoft.com/download/en/details.aspx?id=27746](http://www.microsoft.com/download/en/details.aspx?id=27746), install, restart visual studio... from the link: "A new tool window called C# Interactive is available in Visual Studio by invoking View -> Other Windows -> C# Interactive from the menu." – ckozl Dec 28 '11 at 19:10
  • 5
    Link is dead. Looks like MS has killed the 2010 version. If you've got 2012 you might try this: http://www.microsoft.com/en-us/download/details.aspx?id=34685 – John Fouhy Dec 19 '12 at 23:25
  • ScriptCS appears to be the best stand-alone REPL, built on top of the Roslyn APIs and using NuGet as a package manager: https://github.com/scriptcs/scriptcs/ – dperish Nov 16 '14 at 23:38

10 Answers10

25

The REPL demo was part of "what might happen next", i.e. after 4.0; in .NET 5.0 or something similar.

This is not 4.0 functionality, and never has been.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • I assumed that he demonstration was in response to this post to a similar technology in Mono: http://tirania.org/blog/archive/2008/Sep-10.html – plinth Jul 27 '09 at 12:56
  • 1
    Yes, Mono's repl is quite good (for those who doesn't know it, get mono, then monodir/bin/gsharp or /bin/gsharp). But I miss the ability of adding functions the same way Anders does. – George Jul 27 '09 at 18:59
  • As an alternative I am using http://www.sliver.com/dotnet/SnippetCompiler and Mono's REPL currently, but it would be really nice to have a decent C# Repl. – George Jul 27 '09 at 19:05
  • @DamianPowell depends on your perspective ;p At the time, the OP was expecting the REPL to be included in part of .NET 4.0 BCL, which is clearly not the case since it wasn't 4.0 functionality. – Marc Gravell Feb 05 '13 at 08:29
9

It's probably worth mentioning that the Mono project already does have a C# REPL which i tend to use for those small checks you do now and then. Take a look. Also, if I'm testing an idea which I'm uncomfortable Mono is going to handle to well and it's not worth starting a new test project then Snippet Compiler always comes in handy.

EightyOne Unite
  • 11,665
  • 14
  • 79
  • 105
4

The Immediate window (Debug>Windows>Immediate Ctrl+D, I ) is fairly good replacement that's built in. It does require you start the IDE and put a breakpoint on something.

It does give you the context of where you would like to do experimentation.

Kevin Driedger
  • 51,492
  • 15
  • 48
  • 55
  • 1
    Immediate mode will not do c# lambdas :( – bradgonesurfing Nov 28 '12 at 08:24
  • 1
    That's a hard pill to take: lambdas are sure nice and using them in immediate window and also in edit and continue would make for much better visual studio experience. – Kevin Driedger Dec 03 '12 at 15:41
  • Immediate window is a joke compared to a REPL - it is designed to help you with debugging, nothing more. A real REPL is always available and once you have loaded all dependencies there are no restrictions on what you can do. In the Immediate window you can't create classes. You can't create methods. You can't redefine code. Lambdas. Etc. You can invoke methods, change the value of a property and create variables. That's it. If you ever really used a REPL you should know that the Immediate window is far far away from being a replacement - one simply cannot replace a motorbike with a tricycle. – Unknown May 08 '15 at 13:01
  • The real deal is live editing of code using a tool that's aware of the state of the system... think REPL with code browser. It seems to me that Smalltalk is the model that we should be seeking (and yes, add/remove fields/methods/classes edit the body of the method, and examine the state of the program) – Kevin Driedger May 27 '15 at 18:16
3

Marc's answer is entirely correct, the possibility of a repl or script like c# has been discussed by Eric Lippert in two blog posts:

I would add that, the 2010 CTP does contain an f# repl (not much use for c# but if you were interested in some aspect of the BCL or CLR then it might be sufficient for your needs)

I find that LINQPad makes up for the lack of a REPL in many cases. It would be nice to get it integrated into Visual studio so you could interact with your existing code base more easily though.

ShuggyCoUk
  • 36,004
  • 6
  • 77
  • 101
  • 1
    The hint about F# Interactive is very helpful. I use this often to quickly test out stuff like the Regex classes, networking classes, etc. – Armentage Oct 24 '10 at 17:08
  • 2
    I tend to use PowerShell when I want to test out something in the framework. This is even easier now we have the Package Manager Console. Obviously, this won't help you test out something in the C# language. – Damian Powell Feb 05 '13 at 08:14
2

Take a look at this C# REPL Script Environment which is a great way to quickly run C# script (and learn how to code)

Dinis Cruz
  • 4,161
  • 2
  • 31
  • 49
2

I just published a VisualStudio Extension that provides a REPL environment inside VisualStudio (namely a C# REPL Environment with a Fluent API for .NET and VisualStudio)

In addition to being able to write and execute quick C# snippets (in a REPL environment), you can program VisualStudio IDE in real time!

You can install it using VisualStudio's Extension Manager (search for C# REPL) or via the download link at the VisualStudio Gallery page: VisualStudio C# REPL

The VisualStudio C# REPL page also contains more details and code samples.

There is also an Reddit thread on this extension (which contains more code samples).

Let me know what you think of it

Dinis Cruz
  • 4,161
  • 2
  • 31
  • 49
  • Any plans on updating this to VS 2013? – cori Jul 18 '14 at 00:30
  • Yes, I think it is about time to do it. I added this issue to track it (https://github.com/o2platform/FluentSharp.VisualStudio/issues/1). That is open source, so if you (or others) could help it would be great – Dinis Cruz Jul 18 '14 at 09:13
2

Command-line REPL

To play with the C# REPL outside of Visual Studio, open the Developer Command Prompt for VS2015 and type the command csi to begin your interactive session. Here is a list of arguments that can be passed to csi.

Note: csi stands for "CSharp Interactive"

You can also open an interactive window directly from Visual Studio by navigating to View > Other Windows > C# Interactive.

Check out the Roslyn Wiki on the C# Interactive Window.

anishpatel
  • 1,472
  • 1
  • 16
  • 23
1

I found http://kamimucode.com/Home.aspx/C-sharp-REPL/1 . Which seems to be pretty good and I believe also exposes an API to evaluate expressions dynamically

ricardo
  • 1,452
  • 1
  • 22
  • 24
0

To update on this old question c# REPL is now available as part of Visual studio IDE (starting VS 2015 update 1).

Introducing the Visual Studio 'C# REPL'

Tilak
  • 30,108
  • 19
  • 83
  • 131
0

From time to time I want to try out some .NET API instead of wondering about C# language syntax. (There are far more subtleties in API than in the language itself.) If you are only looking for REPL for .NET, good old PowerShell is always with you.

C#:

using System;
using System.Text;

Convert.ToBase64String(Encoding.UTF8.GetBytes("Overflow"));

PowerShell:

[Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes("Overflow"))
Franklin Yu
  • 8,920
  • 6
  • 43
  • 57