Using C# Interactive Shell

Amongst other tools, Mono provides a very interesting C# Interactive Shell that may be very useful on a Raspberry Pi.

Installing C# Shell

C# Shell requires the Mono Framework to be installed on your Raspberry Pi.

Once done, you have to install the shell itself

$ sudo apt-get update
$ sudo apt-get install mono-csharp-shell

Starting C# Shell

Once installed, launch the C# Shell:

$ csharp

Or, for elevated privileges

$ sudo csharp

The shell displays the following lines:

Mono C# Shell, type "help;" for help

Enter statements below.

Let’s play!

Typing Code

Every sentence of C# code may be typed.

A sentence is evaluated when the final ; character is typed (or the closing } characted for a block of code).

var i = 10;

If the sentence evaluates to a non-void value, the value is displayed:


All the Mono/.NET framework is available, either directly (for System namespace):


… or by using the required namespaces:

using System.Globalization;
new CultureInfo("hy-am").DisplayName;
"Armenian (Armenia)";

… or even by loading your own assemblies:

using Raspberry.IO.GeneralPurpose;
var cnx = new GpioConnection();

Exiting C# Shell

You want to quit C# Shell ?


And it’s over.

Installing Mono on Raspberry Pi

Now, how do I use Mono on my Raspberry Pi ?

Installing Mono

First, you have to install the Mono framework, which is pretty easy :

$ sudo apt-get update
$ sudo apt-get install mono-runtime

This will update the package list and install the Mono runtime.

Running Programs

Once done, you’re ready to run Mono/.NET programs.

Usually, a Test.exe program must be started as follow:

mono Test.exe

Or, if your program requires elevated rights:

sudo mono Test.exe

Writing Programs

If you’re familiar with Visual Studio, the best you can do is… to use Visual Studio! Once compiled, programs created with Visual Studio will run on Mono (well, you will soon discover that some restrictions apply).

In order to test your Mono setup, create a new Console application (target it for .NET Framework 2.0 or .NET Framework 4.0):

using System;

namespace Test
    class Program
        static void Main(string[] args)
            Console.WriteLine("Running on {0}", Environment.OSVersion);

            Console.WriteLine("Press a key to continue");

Compile, copy the .exe file to your Raspberry Pi, run the program (mind the case!)

$ mono Test.exe

Enjoy the result!

Running on Unix
Press a key to continue

You will soon discover that there’s a problem with DateTime on hard-float ABI systems. You may choose to use a ‘Soft-float’ Raspbian until a fixed release of Mono is available… but that’s another story!