Very practical Mono C# Shell

in my first tutorial I want to give you a better understanding of the very practical Mono C# shell.
Before I start, I want to give you an introduction about the Mono Framework.

Mono is an open source project which allows you to implement C# and .Net compatible solutions. It supports many platforms including consoles and mobile. The default installer comes with a lot of useful tool for the work with this framework. If you want to develop C# with Mono you can use the command line compiler and a text editor or your favorite IDE with C# support. Mono has also an IDE called Mono Develop. This is a good development environment for the start and is also available for many platforms. I prefer Visual Studio from Microsoft because it has a stronger tool set.

In my opinion C# is one of the most beautiful languages ​​and especially for beginners very suitable. The .Net Framework and associated tools make the development very easy and quick. It is also an interesting solution for larger projects. Many programs in the Windows world are based on this technology. With Mono you can break these walls depending on your intended use. There are even online games being developed with this technology.

The Mono C# Shell provides the possibility to test and run code relatively quickly. I use it a lot to test my implemented calculations or functions without checking the entire project. Another possible application is to generate files which you need to test or to process something.

Before we start, we have to install the Mono Framework. Browse to the product page and download the packages for your system. If you are using a packed management (e.g. Chocolaty) you can also use this. After downloading, install the framework. For Windows you still need to set an environment variable to your install location. For this tutorial we don’t need any IDE or text editor.

Now we are ready to start:

To start the Mono C# Shell open your terminal and type


Now the program should open and we can use it.
If you want to quit the application type (do not forget the semicolon at the end)


Lets define our first variable

int x = 10;

The shell supports the whole C# syntax. For some commands there is also a shortened notation. For example if you get return-value it outputs directly.
Lets try this with your variable. Now we add a value

x + 15;

Now the result should appear directly. Lets try it with comparing two strings without defining variables

"Hello" == "World!";

If you want to assign a new value to your variable do it like in C#

x = x / 2;

Lets define another

int y = 2;

We can also look at all the defined variables


You can use your variables like any C# object

string hello = "Hello";

The next step is loading references


This is the equivalent of invoking the compiler with the -pkg: flag. Specifically, it integrates Mono libraries with Unix’s pkg-config. Packages allow definitions and multiple assemblies to be loaded in a single call. Let’s try an advanced exsample

LoadPackage ("gtk-sharp-2.0");
using Gtk;
Application.Init ();
var b = new Button ("Hello Interactive Shell");
var w = new Window ("So cute!");
b.Clicked += delegate { Application.Quit (); };
w.Add (b);
w.ShowAll ();
Application.Run ();

If you want to use a namespace, it behaves just as in C#

using System.IO

I hope my first tutorial helped you and I wish you much fun with experimenting.


Leave a Reply