Home > Uncategorized > C# Tutorial – Your first C# program

C# Tutorial – Your first C# program


Let us quick start to write our first C# program. This tutorial was first written for 2008 C# Express edition, but the concept should apply to the newer 2010 C# Express Edition.

Start Visual C# Express. Note that it takes slightly more time as the installation configures the environment for the first time. Once C Sharo starts running, select File -> New project. From the New project dialog -> select Console application. Console Application is the most basic application type on a Visual C#. Visual C# Express now creates a new project and creates a new file named Program.cs. It should look something like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

// We will learn about namespace later
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
}
}
}

This is the basic skeleton of a C# program. It does not really do anything. We want to add some code to it. Here it goes.

Console.WriteLine(“Hello, world! – I learned this from Starredreviews”);
Console.ReadLine();

The whole thing now should look as follows

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{

Console.WriteLine(“Hello, world! – I learned this from Starredreviews “);
Console.ReadLine();
}
}
}

To run this code press F5. This will compile the program, assuming you did not make any more typing mistakes. It will give you a Window that will display – Hello, world! – I learned this from Starredreviews

Let us understand a little bit about the code. The first line

Console.WriteLine(“Hello, world! – I learned this from Starredreviews “);

prints a line onto the console window. The second line

Console.ReadLine();

reads a line of input. If we do not include it, the program, when run, will print a line and come back to the development tool window. You may like to see the action with and without the second line of the code.

This completes running your first C# program. We will slowly be implementing more codes and understand the nuts and bolts of the C Sharp programming language.

Categories: Uncategorized Tags:
  1. No comments yet.