C# Console/CLI Interpreter?

后端 未结 17 1898
眼角桃花
眼角桃花 2020-12-24 07:57

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(\"bla

相关标签:
17条回答
  • 2020-12-24 08:05

    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.

    0 讨论(0)
  • 2020-12-24 08:05

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

    • Snippet Compiler

    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.

    0 讨论(0)
  • 2020-12-24 08:07

    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".)

    0 讨论(0)
  • 2020-12-24 08:07

    The Roslyn project sources contain a REPL called CSI (http://sourceroslyn.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).

    0 讨论(0)
  • 2020-12-24 08:10

    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

    0 讨论(0)
  • 2020-12-24 08:10

    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.

    0 讨论(0)
提交回复
热议问题