我想你要寻找的是LINQPad
。它可以让你运行一小段代码,而无需制作一些一次性的控制台应用程序来测试。为了好玩,我写了以下内容,它将编译和执行文本框中的任何内容。
void Main()
{
TextBox textBox = new TextBox()
{
Multiline = true,
Size = new Size(200, 60),
Text = @"string x = ""hello"";int myLength;myLength = x.Length;MessageBox.Show(myLength.ToString());"
};
Button button = new Button()
{
Location = new Point(0, 60)
};
button.Click += new EventHandler(delegate(object sender, EventArgs e)
{
var csc = new CSharpCodeProvider(new Dictionary<string, string>() { { "CompilerVersion", "v3.5" } });
var parameters = new CompilerParameters(new[] { "mscorlib.dll", "System.dll", "System.Windows.Forms.dll" }, "foo.exe", true);
parameters.GenerateExecutable = true;
CompilerResults results = csc.CompileAssemblyFromSource(parameters,
@"
using System.Windows.Forms;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
" +
textBox.Text
+ @"
}
}
}
");
Process proc = Process.Start("foo.exe");
}
);
Form f = new Form
{
Controls = { textBox, button }
};
Application.Run(f);
}
其实我写的LINQPad
但它会很容易得到Visual Studio
运行如果你只是想工具,下载http://www.linqpad.net/ – TrueWill 2010-12-01 22:14:21