C# 控制台?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47537/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 09:59:36  来源:igfitidea点击:

C# Console?

提问by FlySwat

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.

有谁知道是否有类似于 Python 或 Ruby 控制台的 ac# Console 应用程序?我知道整个“编译与解释”的区别,但我认为使用 C# 的反射能力是可以做到的。

UPDATEWell, 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.

UPDATE嗯,它只花了大约 200 行,但我写了一个简单的...它的工作原理很像 osql。您输入命令,然后使用 go 运行它们。

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

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

If anyone wants it, let me know.

如果有人想要,请告诉我。

采纳答案by S?ren Kuklau

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.

鉴于您提到“C# 的反射能力”,我不确定您是在寻找一个交互式 C# 控制台来处理您自己的小代码片段(如 Ruby 的irb),还是一种与当前运行的现有编译应用程序交互的方式一个过程。

In the former case:

在前一种情况下:

  • Windows PowerShellmight be your friend
  • Another candidate would be the C# shell
  • Finally, CSI, a Simple C# Interpreter
  • Windows PowerShell可能是您的朋友
  • 另一个候选者是C# shell
  • 最后,CSI,一个简单的 C# 解释器

回答by LJ.

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.aspxhas 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#.

谷歌揭示了这方面的一些努力。其中一个特别说明了为什么这不像看起来那么简单。 http://www.codeproject.com/KB/cs/csi.aspx有一个基本的解释器,它使用 .NET 的内置能力来编译 c# 代码。一个关键问题是作者的方法为每个解释的行创建了一个新的迷你 .NET 程序集。C# 可能具有 Python 或 ruby​​ 样式控制台的反射能力,但 .NET 框架库面向编译 C#,而不是动态解释它。如果您对此很认真,您可能需要查看http://www.paxscript.net/,这似乎是对解释型 C# 的真正尝试。

回答by Dale Ragan

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 SnippetCompilercould be a good fit.

我不确定您正在寻找这个应用程序来完成什么。如果只是尝试一些代码而不必创建项目和所有开销来测试一个想法,那么SnippetCompiler可能是一个不错的选择。

I just wanted to give you another option.

我只是想给你另一种选择。

回答by Daren Thomas

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

在 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.

这个想法很简单:通过改变编译器来动态生成和执行代码,而不是仅仅生成静态代码,从而创建一个交互式 C# shell。

回答by FlySwat

It appears Miguel De Icaza was stalking me:

Miguel De Icaza 似乎在跟踪我:

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

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

回答by AR.

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

如果你不具备使用控制台,只想一个地方来测试一些特设C#代码片段,然后LinqPad是一个不错的选择。我觉得它非常酷/易于使用。

回答by aleemb

I believe you are looking for Snippy=)

我相信你正在寻找Snippy=)

Snippy Screenshot

Snippy 截图