Anders Hejlsberg 的 C# 4.0 REPL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1187423/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Anders Hejlsberg's C# 4.0 REPL
提问by George
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.
在 Ander 的演讲The Future of C#的最后 10 分钟中,他演示了一个非常酷的 C# Read-Eval-Print 循环,这将对学习该语言有很大帮助。
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?
多个 .NET4 相关下载已经可用:Visual Studio 2010 和 .NET Framework 4.0 CTP、Visual Studio 2010 和 .NET Framework 4 Training Kit。你知道这个 REPL 发生了什么吗?它是否隐藏在示例中?
I know about mono repl. Please, no alternative solutions.
我知道单声道复制。请,没有替代解决方案。
采纳答案by Marc Gravell
The REPL demo was part of "what might happen next", i.e. after4.0; in .NET 5.0 or something similar.
REPL 演示是“接下来会发生什么”的一部分,即4.0之后;在 .NET 5.0 或类似的东西中。
This is not4.0 functionality, and never has been.
这不是4.0 的功能,而且从来都不是。
回答by ShuggyCoUk
Marc's answer is entirely correct, the possibilityof a repl or script like c# has been discussed by Eric Lippert in two blog posts:
Marc 的回答完全正确,Eric Lippert 在两篇博客文章中讨论了像 c# 这样的 repl 或脚本的可能性:
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 CLRthen it might be sufficient for your needs)
我要补充一点,2010 CTP 确实包含 f# repl(对 c# 没有太大用处,但如果您对BCL 或 CLR 的某些方面感兴趣,那么它可能足以满足您的需求)
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.
我发现 LINQPad 在很多情况下弥补了 REPL 的不足。最好将它集成到 Visual Studio 中,这样您就可以更轻松地与现有代码库进行交互。
回答by EightyOne Unite
It's probably worth mentioning that the Mono project already doeshave 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 Compileralways comes in handy.
这也许值得一提的是,Mono项目已经确实有一个C#REPL我倾向于使用那些你偶尔做些小检查。 看一看。此外,如果我正在测试一个我不舒服的想法,Mono 会很好地处理并且不值得开始一个新的测试项目,那么Snippet Compiler总是派上用场。
回答by Kevin Driedger
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.
即时窗口 (Debug>Windows>Immediate Ctrl+D, I) 是内置的相当不错的替代品。它确实需要您启动 IDE 并在某些东西上放置断点。
It does give you the context of where you would like to do experimentation.
它确实为您提供了您想要进行实验的背景。
回答by ricardo
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
我找到了http://kamimucode.com/Home.aspx/C-sharp-REPL/1。这似乎很好,我相信还公开了一个 API 来动态评估表达式
回答by Dinis Cruz
Take a look at this C# REPL Script Environmentwhich is a great way to quickly run C# script (and learn how to code)
看看这个C# REPL 脚本环境,这是快速运行 C# 脚本(并学习如何编码)的好方法
回答by Dinis Cruz
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)
我刚刚发布了一个 VisualStudio 扩展,它在 VisualStudio 中提供了一个 REPL 环境(即带有 Fluent API 的 C# REPL 环境,用于 .NET 和 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!
除了能够编写和执行快速的 C# 代码片段(在 REPL 环境中),您还可以实时编程 VisualStudio IDE!
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
您可以使用 VisualStudio 的扩展管理器(搜索 C# REPL)或通过 VisualStudio 库页面上的下载链接安装它:VisualStudio C# REPL
The VisualStudio C# REPLpage also contains more details and code samples.
在VisualStudio的C#REPL页面还包含更多的细节和代码示例。
There is also an Reddit thread on this extension(which contains more code samples).
此扩展程序上还有一个Reddit 线程(其中包含更多代码示例)。
Let me know what you think of it
告诉我你对它的想法
回答by Tilak
To update on this old question c# REPL is now available as part of Visual studio IDE (starting VS 2015 update 1).
为了更新这个老问题,c# REPL 现在作为 Visual Studio IDE 的一部分提供(从 VS 2015 更新 1 开始)。
回答by anishpatel
Command-line REPL
To play with the C# REPL outside of Visual Studio, open the Developer Command Prompt for VS2015and type the command
csi
to begin your interactive session. Hereis a list of arguments that can be passed to csi.Note:
csi
stands for "CSharp Interactive"
命令行 REPL
要在 Visual Studio 之外使用 C# REPL,请打开VS2015的开发人员命令提示符并键入命令
csi
以开始交互式会话。这是可以传递给 csi 的参数列表。注:
csi
代表“CSharp Interactive”
You can also open an interactive window directly from Visual Studio by navigating to View > Other Windows > C# Interactive
.
您还可以通过导航到View > Other Windows > C# Interactive
.
Check out the Roslyn Wiki on the C# Interactive Window.
在C# Interactive Window上查看 Roslyn Wiki 。
回答by Franklin Yu
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 PowerShellis always with you.
有时我想尝试一些 .NET API 而不是想知道 C# 语言语法。(API 中的微妙之处远多于语言本身。)如果您只是在寻找 .NET 的 REPL,那么好的旧PowerShell始终与您同在。
C#:
C#:
using System;
using System.Text;
Convert.ToBase64String(Encoding.UTF8.GetBytes("Overflow"));
PowerShell:
电源外壳:
[Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes("Overflow"))