C# Development Environment For Beginners

C# programs can be written using

  • Text editors like Notepad.
  • Visual Studio Tools.
For serious development Visual studio should be used. Visual Studio express edition is available for free download. Visual Studio express edition do not have all the features of Visual Studio full version but will suffice for standard development work.

Hello World! using Notepad

Let's write a "Hello World" program using Notepad.
  • Go to Start->Run and type notepad. Hit 'Enter' key or 'OK' button.
  • In the resulting window copy paste the below code.
    Its okay if you do not understand the below syntax. In the later part of the tutorial we will cover the C# syntax.
        using System; 
    
        namespace HelloWorld
        { 
            class Program 
            {
                static void Main(string[] args)
                {
                    Console.WriteLine("Hello World!"); 
                    Console.ReadLine(); 
                } 
            } 
        }
        
  • Save the file as HelloWorld.cs
  • Now go to visual studio command prompt by following the path Start > All Programs > Microsoft Visual Studio 2010 or whatever visual studio version you have available > Visual Studio Tools > Visual Studio Command Prompt.
  • Using the command prompt go to the directory where you saved HelloWorld.cs file.
  • Now type csc HelloWorld.cs and hit 'Enter' key.
  • At this stage if you do not get any error then your first C# program has been successfully compiled.
  • Double click the 'HelloWorld.exe' file created in the same folder and hello world! message should appear.

Hello World! using Visual Studio

Let's write a "Hello World" program using Visual Studio.
  • Start Visual Studio and go to File > New Project.
  • Select Visual C# in the left pane and Console Application on the right.
  • Give your project a name and specify a location where it will be saved. Click on "OK" button.
  • A program.cs file should get created by default.
  • Now copy the same "Hello World" code mentioned above to the Program.cs file.
  • Press 'CTRL+F5' key to run the application.
  • The same "Hello World!" output should get displayed.
Congratulations! you have successfully created a Hello World Application.