关于 C#:
为了让您C#从 a 运行应用程序cmd,需要执行以下步骤:
- 转到
C:\Windows\Microsoft.NET\Framework\v4.0.30319文件系统上的位置并复制路径。
- 现在右键单击
Computer转到属性。
- 在 下
System Properties,选择Advanced选项卡,然后单击Environment Variables。
- 在
Environment Variables下User Variables,选择New。
- 对于
Variable Name写CSHARP_HOME或其他东西,虽然我使用相同的进一步需要解释这一点。Variable Value仅用于Paste您在步骤 1中复制的内容。单击确定。
- 再次执行第 4 步,如果
path变量不存在,否则您可以简单地选择path然后单击Edit以执行下一个操作(将;(分号)放在末尾Variable Value并写入%CSHARP_HOME%\(或使用您在第 5 步中使用的内容) )。这次为Variable Namewritepath和 for Variable Valueuse%CSHARP_HOME%\并单击 OK。
- 打开
cmd并键入csc并按ENTER,您可能会看到类似这样的输出

- 现在考虑我在这个位置为我的 CSharp 项目(在文件系统上)创建一个目录结构
C:\Mine\csharp\command。在这里,我在文件夹中创建了两个文件command夹。源和构建。
- 现在从任何
Text Editor创建一个小示例程序(我使用的是 Notepad++),如下所示,将其保存WinFormExample.cs在source文件夹下:
using System;
using System.Drawing;
using System.Windows.Forms;
namespace CSharpGUI {
public class WinFormExample : Form {
private Button button;
public WinFormExample() {
DisplayGUI();
}
private void DisplayGUI() {
this.Name = "WinForm Example";
this.Text = "WinForm Example";
this.Size = new Size(150, 150);
this.StartPosition = FormStartPosition.CenterScreen;
button = new Button();
button.Name = "button";
button.Text = "Click Me!";
button.Size = new Size(this.Width - 50, this.Height - 100);
button.Location = new Point(
(this.Width - button.Width) / 3 ,
(this.Height - button.Height) / 3);
button.Click += new System.EventHandler(this.MyButtonClick);
this.Controls.Add(button);
}
private void MyButtonClick(object source, EventArgs e) {
MessageBox.Show("My First WinForm Application");
}
public static void Main(String[] args) {
Application.Run(new WinFormExample());
}
}
}
- 现在输入
csc /out:build\WinFormExample.exe source\WinFormExample.cs(最后给出更多信息,用于编译器选项)并按下ENTER编译,如下所示:

- 现在只需使用 运行它
.\build\WinExample,如下所示:

- 现在你的简单
GUI Application已经启动并运行了:-)
请让我知道,Java如果需要的话,我也可以解释同样的事情:-)
有关更多信息,请Compiler Options参阅按字母顺序列出的 C# 编译器选项