想在ubuntu 14.04 上开发C#, 能用的有Mono
Mono is a runtime environment that can run .NET applications and that works on both Windows and Linux. It includes a C# compiler.
1. install Mono with sudo apt-get install monodevelop
As of Ubuntu 14.04, the executable for MonoDevelop will be found at: /usr/bin/monodevelop
2. 控制台 Hello World
//hello.cs
using System; public class HelloWorld { static public void Main () { Console.WriteLine ("Hello Mono World"); } }
使用命令 mcs hello.cs 编译之后会产生一个hello.exe, 可以使用命令 mono hello.exe 运行,输出结果为: Hello Mono World
3. Winforms Hello World
// hello_win.cs
using System; using System.Windows.Forms; public class HelloWorld : Form { static public void Main () { Application.Run (new HelloWorld ()); } public HelloWorld () { Text = "Hello Mono World"; } }
使用命令 mcs hello.cs -pkg:dotnet
编译会报错,需要使用 mcs helloWinforms.cs -pkg:dotnet -lib:/usr/lib/mono/2.0 (我使用的是ubuntu14.04)
使用命令 mono hello.exe
运行