JADSB Just another data science blog

Programming in C# for People Who Like Vim

As someone working in the mobile gaming industry, I wanted to learn more about the nuts and bolts of game making. To get hands-on experience, I am taking C# Programming for Unity Game Development from . The first step in learning any programming language is to setup the development environment. The course instructor suggested using either Visual Studio or MonoDevelop, but I am a fan of Vim. In this post, I will document my initial experience in programming with C# from the terminal on macOS.

  1. Installing Mono

    In order to compile C# code, you would need Mono, “a free and open source .NET Framework-compatible software framework”. Using brew, you can install Mono via the following command:

    brew install mono
    
  2. Hello World on C#

    Here is my first program in C#:

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

    You can compile it with the csc command:

    csc HelloWorld.cs
    

    Now, you can run the code with mono command

    mono HelloWorld.exe
    
  3. Compiling with DLL

    If the project you are working on has dynamic link library (DLL), you can compile the code with the -reference option

     csc -reference:foo.DLL Program.cs
    

Final Thoughts

So far, writing C# code on macOS seems straightforward. Though, the course involves using Unity. I might end up needing the functionalities in Visual Studio later.

Copyright © B.S. Chan