How to do C# and .Net Programming in Ubuntu using Mono

Posted in:Tips 'n Tricks

C#(pronounced C sharp and not C hash), is a rich object oriented programming language within the .Net framework developed by Microsoft. Does this mean you have to switch to Windows to program in C#? Not at all!!!

Although C# was developed by Microsoft as a strategy to pull many programmers from programming in Linux to Windows,that is to make C# programs execute only in Windows.Thankfully,a open source company named Ximian started a project called Mono in the year 2001.Mono was later developed by Novell and is still under development by Novell.Mono brings to Linux an Integrated Development Environment for C#.Mono was primarily developed to support C# and .net programming,although it supports various other languages such as python,java,vala,etc.That said,let us install Mono in Ubuntu:

Open Ubuntu software center and type mono in the search box,now choose MonoDevelop package in the list and Install.

In Terminal,

sudo apt-get install monodevelop

After the installation start MonoDevelop,you should see an aesthetic programming environment.

Mono

To start programming select

File  ->  New  ->  File..

Select C# and general

Build the program:press F7

Run the program:ctrl+F5

NOTE:This is very important,the console in MonoDevelop 2.4 does not read input.This is a bug in mono and has already been reported.To execute programs with ReadLine statements please follow the following steps:

After installing MonoDevelop

  • Create the program using Vim editor,
vim Demo1.cs
  • Now install a package called mono-mcs,which is a c# compiler,
sudo apt-get install mono-mcs
  • Compiling the program and generating .exe file,
mcs Demo1.cs
  • Executing the program,
mono Demo1.exe

C#

It is worth mentioning about mono-extras.Mono-extras provide great flexibility in programming.Since mono is developed by Novell,there is no deb packages of mono-extras available.If you are working in another Linux rpm based distros,then you can download mono-extra packages from http://pkgs.org/package/mono-extras

The plugins and the description of support for variety of databases in the mono-extras package is in the following link http://www.mono-project.com/RPM_Packages_Descriptions

Oracle+Linux users can have nothing better than this,mono is well integrated with Oracle database,thus allowing you to write programs in C# that can create a table and also be able to store and fetch data from the database.Please refer this link for installing oracle plugin http://www.mono-project.com/Oracle#Info

Enjoy Mono!!!

Press the button below if you liked this site.
Sam_Benny's picture

Lets just say,I love programming and like my Linux box.Trying out new stuff everyday in Linux gave me great insight into computers.Computer researcher and a humble boy.You can follow me in twitter @msambenny

writeforus