How to run a Program in C Sharp

Jul 06, 2012, by admin

c-sharp-logoC# is a great programming language, and all the tools you need to get started are free and easy to use. While C# is usually associated with Microsoft and closed source, Free software supporters just use DotGNU that delivers more or less the same basic knowledge and allows to study and change internals without restrictions. The instructions below describe both “FOSS oriented” and “Windows oriented” approaches. C# is also used with .NET framework.

c-sharp-logo-2Steps to run a Program in C Sharp

Set up (Windows way)

1.Go here to download your free copy of Visual C# 2010 Express Edition

2.Run the downloaded executable and follow these steps: 

  1.     Next.
  2.     I agree → Next.
  3.     Select MSDN, not SQL → Next.
  4.     Install.

Run your first program

  1. Run Visual C# 2005 Express Edition.
  2. Go to File → New → Project.
  3. Select Visual C# → Windows → Console Application.
  4. Press OK.

You should see this:

using System;

using System.Collections.Generic;

using System.Text;

namespace ConsoleApplication1

{

  class Program

  {

    static void Main(string[] args)

    {

    }

  }

}

5.Beneath static void Main(string[] args), after the first curly brace, type:

Console.WriteLine(“Hello, World!”);

Console.ReadLine();

It should look like this:

using System;

using System.Collections.Generic;

using System.Text;

namespace ConsoleApplication1

{

  class Program

  {

    static void Main(string[] args)

    {

      Console.WriteLine(“Hello, World!”);

      Console.ReadLine();

    }

  }

}

6.Click the Run button on the toolbar.

Congratulations! You created your first C# program!

c-sharpSet up (Free software way)

1.You need CVS and GNU build tools. This should be included into the majority of Linux distributions.

2.Go to the DotGNU project (http://www.gnu.org/software/dotgnu/) that provides FOSS implementation of C#. Read the chapter about the installation. These instructions are simple to follow even for beginners.

3.You can choose to get the source code and build you C# environment from scratch or you may try precompiled distributions first. The project is relatively easy to build from the source so we suggest to try this way first.

4.Try to start some examples that also come in precompiled (.exe) form. For instance, FormsTest.exe will show large collection of various GUI controls. The folder pnetlib/samples contains the script ilrun.sh that can launch precompiled executables, for instance sh ./ilrun.sh forms/FormsTest.exe (from inside that folder).

5.Under Linux, you can use KWrite or gedit to edit the C# code – the recent versions of both editors support the syntax highlight for this language.

6.Figure out yourself how to compile the short example, given in the “Windows way” section. If the project web site does not provided enough documentation, try web search. If this does not help, post questions to the project mailing lists.

c-sharp-logo-1Congratulations, you are both C# – aware and not bound to any single C# provider!