Tuesday, June 2, 2009


How to Create a Program in C Sharp


from wikiHow - The How to Manual That You Can Edit

C# 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 modify internals without restrictions. Instruction below describe both "FOSS oriented" and "Windows oriented" approaches.

Steps



Set up (Windows way)

  1. Go here to download your free copy of Visual C# 2005 Express Edition, or here to download VC# 2008 Express Edition (choose Visual C# language then click download).
  2. Run the downloaded executable and follow these steps:

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


Create 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!

Set up (Free software way)
  1. You need CVS and GNU build tools. This should be included into majority of Linux distributions.
  2. Go to 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 ever for beginner.
  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.

Congratulations, you are both C# - aware and not bound to any single C# provider!

Tips


  • There are more good C# implementations than the two described here. Mono project may be interesting for you as well.
  • Visual C# 2005/2008 Express Editions comes with an option to install the Microsoft MSDN 2005 Express Edition. This is a great reference and can be accessed through Help:Contents or by highlighting a keyword and pressing F1. It is strongly recommended that you download and install the MSDN library.


Recommended Books




Related wikiHows




Sources and Citations





Article provided by wikiHow, a wiki how-to manual. Please edit this article and find author credits at the original wikiHow article on How to Create a Program in C Sharp. All content on wikiHow can be shared under a Creative Commons license.