November 30, 2013

Kick-Start C# : Your first program

Open up Visual Studio. I have Visual Studio 2012 at hand.

Go to File -> New -> Project.
A new window will become visible. From the Templates on the left, select Visual C#. Select Console Application.
Give it a name, any name.


Then click OK.

You will see that the following screen will be live on your Visual Studio.


On the right, the tab is called the Solution Explorer. You will see that the name you have given while opening your new project is visible on the Solution Explorer. There's a bunch of items you can see on that explorer. The Program.cs is the C# file that you will be working on.

The first thing that we do is like the following:

using System;

namespace MyFirst
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Lets see how it works!");
        }
    }
}
Once you are done, hit F5. You will notice that a black screen that we call Console just become visible and vanish again. What happened? Just add another line and you will see the black screen not popping out like the previous case. Here's the updated code. Hit F5 again.
using System;

namespace MyFirst
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Lets see how it works!");
            Console.ReadLine();
        }
    }
}
The code on line 10 allows the Console to stay alive.

That was easy. Keep experimenting with whatever you got to see on the Console. Just write it down inside the WriteLine quotes.
In the next post, we will explore further about what we have seen now.