Create a Program in C Sharp

Revision as of 00:00, 8 December 2016 by Kipkis (Kipkis | contribs) (importing article from wikihow)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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. The instructions below describe both "FOSS oriented" and "Windows oriented" approaches. C# is also used with .NET framework.

Steps

Set up (Windows way)

  1. Go here to download your free copy of Visual C# 2010 Express Edition. Also available are the 2012 express products, but go with 2010 if you are looking for general c# development.
    • Also, 2012 does not work without Windows 7/8.
  2. Run the downloaded executable and follow these steps:
    • Next.
    • I agree → Next.
    • Select MSDN, not SQL → Next.
    • Install.

Create your first program.

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

    You should see this:
  5. Beneath static void Main(string[] args), after the first curly brace, type:
  6. It should look like this:
  7. Click the Run [►] button on the toolbar.
    Congratulations! You created your first C# program!
  • This should have produced a console windows, reading Hello World!
  • if it did not, then you did something incorrectly.

Set 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 pre-compiled 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.
  7. Congratulations, you are both C# - aware and not bound to any single C# provider!

Tips

  • If installing Visual C# 2010/2012 express, it will either automatically download or give you the option to do this.
  • 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.
  • There are more good C# implementations than the two described here. Mono project may be interesting for you as well.

Recommended Books

Related Articles

Sources and Citations