28

Does anyone know if there is a c# Console app, similar to the Python or Ruby console? I know the whole "Compiled versus Interpreted" difference, but with C#'s reflection power I think it could be done.

UPDATE Well, it only took about 200 lines, but I wrote a simple one...It works a lot like osql. You enter commands and then run them with go.

SharpConsole http://www.gfilter.net/junk/sharpconsole.jpg

If anyone wants it, let me know.

FlySwat
  • 172,459
  • 74
  • 246
  • 311
  • 3
    Awesome! Where could one download your console?? – georgiosd Feb 28 '11 at 13:57
  • 6
    The image is broken. – Teo Klestrup Röijezon Jul 02 '11 at 01:44
  • I'd like to try your app/solution as well. Any thought to releasing/sharing the app and or its source code? Perhaps host on GitHub, SourceForge, or CodePlex. I assume it would be easy to compile from source as it's only 200 lines. – David Mar 02 '12 at 22:58
  • 1
    @FlySwat hasn't been online since Jan '11 – Basic Jun 26 '12 at 16:54
  • 1
    @Basic It makes me think the guy might even have passed away. It's sad , but under what other circumstances someone with 46k rep would just abandon the account? – Camilo Martin Feb 08 '13 at 07:01
  • 3
    @Basic Worst of all is that I can't even google the guy, with a nick like that. If he did pass away, some relative might like to hear that even with zero activity for two years, he still is a top 0.31% user with a huge reputation that keeps rising even long after he made contributions to a mostly-meritocratic community where reputation is mostly correlated with being a nice guy. – Camilo Martin Feb 08 '13 at 10:50
  • The best Option is using CSharpRepl take a look at my answer: https://stackoverflow.com/a/76761036/11971428 – AmirJabari Jul 25 '23 at 09:05

7 Answers7

19

Given your mention of "C#'s reflection power", I am unsure whether you're looking for an interactive C# console for small code snippets of your own (à la Ruby's irb), or a means of interacting with an existing, compiled application currently running as a process.

In the former case:

  • Windows PowerShell might be your friend
  • Another candidate would be the C# shell
  • Finally, CSI, a Simple C# Interpreter
Sören Kuklau
  • 19,454
  • 7
  • 52
  • 86
  • That C# shell isn't a shell at all. It does takes your shebang prefixed "script" and wraps it up in Main(){} – mpen Jan 17 '12 at 06:54
  • Powershell isn't ideal if you don't want the hassle to learn and use a new scripting/coding syntax. It's different from C#. Wish Powershell was more like Beanshell is to Java. – David Mar 02 '12 at 23:01
9

Found this on reddit: http://tirania.org/blog/archive/2008/Sep-08.html

Quote from the site:

The idea was simple: create an interactive C# shell by altering the compiler to generate and execute code dynamically as opposed to merely generating static code.

Daren Thomas
  • 67,947
  • 40
  • 154
  • 200
8

If you don't have to use the console, and just want a place to test some ad hoc C# snippets, then LinqPad is a good option. I find it very cool/easy to use.

AR.
  • 39,615
  • 9
  • 44
  • 52
  • This is a great tool for the job, thanks! I had it already but had never tried it just to run code. It's nice because it also runs VB, and can run expressions or statements, as well as obviously execute LINQ2SQL against a live database, and run regular SQL queries. – gregmac Feb 16 '11 at 22:02
6

I am not sure what you are looking for this application to accomplish. If it is just to try some code without having to create a project and all the overhead to just test an idea, then SnippetCompiler could be a good fit.

I just wanted to give you another option.

Dale Ragan
  • 18,202
  • 3
  • 54
  • 70
  • Not as quick and easy as script interpreters, but by far the most useful that I've tried. Nice to be able to easily add a bunch of references to my libraries. Thanks Dale! – Jason Mar 04 '10 at 17:51
3

It appears Miguel De Icaza was stalking me:

http://tirania.org/blog/archive/2008/Sep-08.html

FlySwat
  • 172,459
  • 74
  • 246
  • 311
1

Google reveals a few efforts at this. One in particular illustrates why this is less straightforward than it might seem. http://www.codeproject.com/KB/cs/csi.aspx has a basic interpreter using .NET's built in ability to compile c# code. A key problem is that the author's approach creates a new mini .NET assembly for each interpreted line. C# may have the reflective power to have a python or ruby style console, but the .NET framework libraries are geared toward compiling C#, not dynamically interpreting it. If you are serious about this, you may want to look at http://www.paxscript.net/, which seems like a genuine attempt at interpreted C#.

LJ.
  • 875
  • 2
  • 9
  • 13
1

I believe you are looking for Snippy =)

Snippy Screenshot

Community
  • 1
  • 1
aleemb
  • 31,265
  • 19
  • 98
  • 114