How to Create a Program in C Sharp

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...

Part 1 of 3:

Seting Up (Windows)

  1. Picture 1 of How to Create a Program in C Sharp
    Go here to download your free copy of Visual C# Community Edition.
  2. Picture 2 of How to Create a Program in C Sharp
    Run the downloaded executable and follow these steps:
    1. Next.
      Picture 3 of How to Create a Program in C Sharp
    2. I agree → Next.
      Picture 4 of How to Create a Program in C Sharp
    3. Select MSDN, not SQL → Next.
      Picture 5 of How to Create a Program in C Sharp
    4. Install.
      Picture 6 of How to Create a Program in C Sharp
Part 2 of 3:

Creating Your First Program

  1. Picture 7 of How to Create a Program in C Sharp
    Run Visual C# Community Edition.
  2. Picture 8 of How to Create a Program in C Sharp
    Go to File → New → Project.
  3. Picture 9 of How to Create a Program in C Sharp
    Select Visual C# → Windows → Console Application.
  4. Picture 10 of How to Create a Program in C Sharp
    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. Picture 11 of How to Create a Program in C Sharp
    Beneath static void Main(string[] args), after the first curly brace, type:
    Console.WriteLine("Hello, World!"); Console.ReadLine(); 
  6. Picture 12 of How to Create a Program in C Sharp
    Make sure it looks 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(); } } } 
  7. Picture 13 of How to Create a Program in C Sharp
    Click the Run [►] button on the toolbar. This will build the program and run the program. Congratulations!
  8. Picture 14 of How to Create a Program in C Sharp
    View the result. This should have produced a console window, reading Hello World!
    1. If it did not, then you did something incorrectly.
Part 3 of 3:

Setting Up (Free Software)

  1. Picture 15 of How to Create a Program in C Sharp
    Download CVS and GNU build tools. This should be included into the majority of Linux distributions.
  2. Picture 16 of How to Create a Program in C Sharp
    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. Picture 17 of How to Create a Program in C Sharp
    Decide if you want 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. Picture 18 of How to Create a Program in C Sharp
    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. Picture 19 of How to Create a Program in C Sharp
    Use KWrite or gedit to edit the C# code - the recent versions of both editors support the syntax highlight for this language.
  6. Picture 20 of How to Create a Program in C Sharp
    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. Picture 21 of How to Create a Program in C Sharp
    Congratulations, you are both C# - aware and not bound to any single C# provider!
Update 05 March 2020
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile