Saturday, November 17, 2012

Hi, fellas

I'm back with another article. This article will help you for compiling and executing c# programs in ubuntu. This c# and .net was developed by Microsoft for solving the problems created by c, c++ languages. The main problems were manual memory management, ugly pointer arithmetic amd ugly syntactical constructs. C# uses CLR(Common Run-time Language), CTS(Common Type System) and CLS(Common Language Specification) to resolve above stated problems. Now-a-days C# is preferred   over java.

Until now, you used to install gcc(C-Compiler) and g++(C++ compiler) and JVM(java Virtual Machine) in ubuntu for compiling and executing C,C++ and Java programs.
In case of compiling and executing c# programs you can have the options of using terminal or using a GUI. I'm going to give both methods here. There is a simple and beautiful software called MonoDevelop. It can handle C,C++,C# and asp.net programs, similar to Visual Studio.

A warning:
This software is still under construction and you may face bugs.... But I've not faced any bugs in MonoDevelopment till now.

Step One:
http://apt.ubuntu.com/p/monodevelop
Open this link, and you'll get as
"Please wait
The package you requested will install shortly."
It'll be installed after you accept the external protocol and it'll be installed via software center.

Step Two:
For what are you waiting? After software center fi1nishes installing MonoDevelopment, open it and start  coding away. But in older versions of ubuntu, the repository for downloading and installing MonoDevelopment won't be available. So when you open that link given in first step, software center might tell you that software not found. So you'll have to add repository to your software sources. Use the following commands:

git clone git@github.com:mono/monodevelop.git


After adding the repository to your software resources, refresh it by using the command

sudo apt-get update

Or you can do it manually in this way:
Open software center, Go to Edit->Software Sources. Click on the tab 'other software' and click on 'add' button. Then you can add the repository https://github.com/mono/monodevelop.git, No need for refreshing software sources, It'll refresh itself. After doing all these, click on the provided in 1st step, then software center will install MonoDevelop in your ubuntu. 

Here is the famous hello world program for C#.

using System;
namespace Hello
{
class Helloworld
{
public static void Main (string[] args)
{
Console.WriteLine ("Hello World!");
}
}
}
 
Open MonoDevelop, click on File->new->solution. A window will open up asking you for selecting either of GTK# project or Console Project. Click on Console Project. Provide any name. Better to provide name as hello for above program. Solution name will be created by itself. Provide a location in ubuntu for storing your project. 

Note: It is better if you create a file and name it as 'c# programs' or something like that. You can use that file for storing your projects.
After you complete all above steps, that program will be opened by the MonoDeveloper itself. No need for typing the program. Happy?

Note: MonoDevelopment will provide only parts of codes for larger programs, so you need to learn C# first.

Now click on Build->Build all or press F8. The program will be built, Now run it by clicking on run and you'll get the output in terminal. 

3 comments:

  1. great one blog .thank u blogger.
    puni :)

    ReplyDelete
    Replies
    1. Thanks a lot.... Read other articles in my blog.... They are informative and good :) and, yeah... Blogger is a great website which allows its users to create a blog for free and offers more than what we expect :)

      Delete
  2. Sorry for the mistakes in this article.... There was spelling mistake for finishing and 'link' was missing from 'click on the provided in 1st step'. Please read it as 'click on the link provided in 1st step'

    ReplyDelete