Developing C# on Archlinux

Developing C# on Archlinux

So I am working on a Go speech today, and I got to a slide where I wanted to mention the C# programming language. Or more importantly, I wanted to mention how some internal teams at Microsoft are switching over from C# to Go!

The only problem with this slide is that I am supposed to be somewhat credible in what I say..

and I have never written a line of C# in my life.

Furthermore I run linux as my primary operating system. So of course I decided it would be a good idea to try to get a C# development environment up and and running on Archlinux. After a total of 10 seconds of searching Google I couldn’t find the step-by-step tutorial I wanted so naturally I am creating one.

So here goes…

 

Install VS Code

C# isn’t scary at all!

Download page for Linux

Tarball for Linux

Okay so you don’t need VS code, but the C# plugin is really legit. It feels like any other programming language!

But feel free to use any text editor you like. We are just going to be banging out a quick and dirty hello world.

If you plan on writing copious amounts of C# I strongly suggest you get VS code. It’s free and works fantastically on Linux.

Install Mono

(Seriously this is all you do)


sudo pacman -S mono

Write your hello world program

Create a new file called HelloWorld.cs anywhere on your file system.

HelloWorld.cs

// A Hello World! program in C#.
using System;
namespace HelloWorld
{
    class Hello 
    {
        static void Main() 
        {
            Console.WriteLine("Hello World!");

            // Keep the console window open in debug mode.
            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
        }
    }
}

Thanks to the official Microsoft docs for the code snippet!

Compile

The mono mcs compiler works very similar to gcc and accepts an -out flag to specify the name of the executable.


mcs -out:helloexe HelloWorld.cs

Run

Then you can run your program!


mono hello.exe

What’s next?

I am going to do some benchmarking with C# and Go and explore some concurrency patterns between the two. Stay tuned for my findings!

LEAVE A COMMENT

0 comment