Getting started with C# in Mac OS X

Days ago, I wrote the reasons why C# is being so popular. Mono project is one of the reasons of it.

So, I’ve decided to try by myself to get an environment in order to work with C# using my mac. In this case I’ve downloaded the .net framework for Mac OS X (at the Mono Project website), and I’ve looked for the C#’s compiler documentation in order to generate the classic “Hello World” application for Mac OS X (10.5.7).

Is pretty easy, just download the mono-project package and double click in the package, follow the installer instructions, after that you can open any text editor and paste this code (I use TextMate):

using System;

using System.Windows.Forms;

public class test {

public static void Main(){

MessageBox.Show(“Hello World”);

}

}

using System;

using System.Windows.Forms;

public class test {

public static voidMain(){

MessageBox.Show(“Hello World”);

}

}

and save it as “hello.cs” inside a new Folder “Hello” in your path ~/username/.

Then, open a terminal (/Applications/Utilities/Terminal) and type this:

mcs hello.cs /r:System.Windows.Forms.dll /out:hello.exe

The command above generates a (dot) .exe file (windows executable) that you can run over any windows platform with .net framework 3.0 installed

Now, let’s go to make a Mac OS X application with:

macpack -n:hello -a:hello.exe -o:Hello

This will generate an app called “hello.app“, inside the folder “Hello“

Executing such file,

Finally, We got a C# application running over Mac OS X thanks to mono-project, so let’s program some apps with C#.