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:

i;
10

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

Environment.OSVersion;
Unix 3.2.27.0

… or by using the required namespaces:

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

… or even by loading your own assemblies:

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

Exiting C# Shell

You want to quit C# Shell ?

quit;

And it’s over.

This entry was posted in Mono Framework by Eric Bézine. Bookmark the permalink.

About Eric Bézine

Having started programming in the early ages of Personal Computer on the family Thomson TO7-70 (i.e with 70KB memory), Eric grew as a software engineer, made Microsoft .NET its favorite playground and is now Platform Architect for a software editor in the tourism market. Apart from programming, the young Eric passed its free time to play Lego and assemble electronics circuits. Time has passed since then! Arrival of "micro-computers", as Raspberry is, having ability to drive external components, as well as respond to external stimuli, opened a range of new opportunities... Let's enjoy them !

3 thoughts on “Using C# Interactive Shell

  1. Hi, I am just getting started with Raspberry Pi and I have been doing C# since it’s 2003, so I very familiar with the language. I am having difficulty in finding an example of how to interface with a 4×3 matrix keypad. Can anyone help?

    Also, where can I find SERIOUS examples of interfacing devices with the GPIO?

    Which interface code is the best? Raspberry.IO? WiringPI? Etc? I can easily do a C# wrapper for WiringPI, but I don’t see any advanced tutorials for serious development. Any help would be greatly appreciated! Thanks!

  2. Hi, I love the IO library, thanks so much!

    Question… has it been tested on Beagleboard Black? Just like the Pi, BBB is running a flavor of Debian (at least in Rev C), so theoretically it should work, but I was curious if anyone has tried it before I purchase one.

    Thanks again!

Leave a Reply

Your email address will not be published. Required fields are marked *