使用Windows自带编译器编译C#的简单例子

1:先将C:\Windows\Microsoft.NET\Framework\v3.5配置到系统环境变量的path里。

2:写C#代码 

demo1.txt

using System;
namespace HelloWorld
{
   class Program
   {
        static void Main(string[] args) {
            Console.WriteLine("Hello World!");
            Console.ReadKey();
        }
    }
}

demo2.txt

using System;
using System.Windows.Forms;

static class ClassApp{
	static void Main() {
		Application.Run(new Form());
	}
}

3:然后再打开cmd,cd到txt文件所在目录下输入如下命令

csc /out: demo1.exe demo1.txt
csc /out: demo2.exe demo2.txt

生成的exe即可执行程序demo,一个是命令行的demo,另一个是图形界面的demo。

你可能感兴趣的:(使用Windows自带编译器编译C#的简单例子)