Book Store  
  Contact Us  
  Links  
  Site Map  
C# Tutorials - introduction

Introduction to C# Programming

 

Microsoft Visual C# is a powerful object orientated programming language in the architecture of the net framework. It has become increasingly popular with the power of C and C++ and ease of use of Java's class system.

Microsoft net framework

C# applications make use of a large collection of interrelated classes that can be used together to create applications in short time. There are classes for text based applications using the System.Console and for form based applications using the Windows.Forms.

Some C# background

When a C# program is compiled into an exe (executable) format, the file is not a standard Windows exe file. It is compiled into IL Code (Intermediate Language Code). This is then interpreted the first time it is run on your computer. The interpreted code is cached on the computer so the next time it is run it will start up and run quicker the next time it is executed.

C# applications run in a virtual machine called a Common Language Run time. Providing your computer has the net framework, your application will run on that computer. You can even write your code in different net languages and the compiler is able to cope with that.

Integrated Development Environments (IDEs)

There are a number of IDEs that support C# programming the most common being :

Both provide good programming facilities colour coding, error checking and other features. The main difference is that the full Visual Studio Express supports all .net languages and includes other development tools.

Creating a C# Application

This section briefly shows how to create a new project for your C# application with C# Express. The method is similar with the full version of Visual Studio.

  1. Start your IDE
  2. Click File -> New... and then select Project Depending on the IDE version, you will be presented with a list of possible project types. Select C# and Windows and then for this example, choose Console Application.
  3. In the Name text box, enter a name for the project which will be the name of exe program.
  4. Click on File -> Close Solution and select a folder, and folder name.

    The project consists of a set of folders with various component files:
    .csproj C# project file
    .sln Visual Studio Solution
    .suo Visual Studio Solution User Options

Creating a 'Hello World' Application

Open the existing project that you have just created by selecting File -> Open Project and finding the .sln Visual Solution. Select the project solution file and assuming that the project is called HelloWorld, the program.cs file should look something like:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace HelloWorld
{
class Program {
static void Main(string[] args) { }
}
}

Modify the static void Main function as follows:


static void Main(string[] args)
{
Console.WriteLine("Hello World");
}


To run the program, press Ctrl and F5 keys at the same time.

Note that you can also run the program by pressing F5, however, it will display the console window and then close straight away. Pressing Ctrl and F5 together will cause the console window to remain open.

You should see the following output:


Hello World
Press any key to continue



Visual Studio Intellisence

Note that Visual Studio uses IntelliSense which is a way of making typing easier by auto completing.