Introduction to C#

Coding in .NET technology with C# is not a complex task. What it matters is full concentration and honesty to C#. Assuming that everyone here have some general programming knowledge. If not doesn't matters lot but read it carefully.
Create a sample console application in visual studio (Read it here an Introduction to VS and Creating console applications). That will leave you with a pre-formatted code file with following structure.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

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



Know it:

After having an eye to the above code file. Those who have their background in programming wouldn't have any problem in understanding those C# statements. But if it looks as an alien language to you don’t panic we will take them off one by one.

The first 4 lines:

The first 4 line are share similar stories. But before understanding those lines let’s begin with the 5th line
namespace Sample – According to msdn namespaces are used to declare a scope for the similar or related data. You can simple understand it as a big container where you store your related containers and data. In the given code namespace is a keyword and Sample is an identifier.
Coming back to first 4 lines. After getting in with namespaces. If we want to use any contents of the namespace we need to specify it at the top of our code file and for that we have the sing System; it means we can now use the contents of the namespace System in our code file. Next three lines repeats the similar story. Read more about namespaces at msdn.

The 9th line:

class Program – Classes are used to define custom types or in simple words we may say classes are used as a container to store related data and functions. More about classes and OOPS at msdn.

The 10th line:

static void Main(string[] args) – Main method is served as the entry point of any C# program. And according to C# language specification entry point of the program should be named as Main.
Here static keyword specifies that you can call the method without having any instance/object of the class.
void means that the Main function wouldn't return any value. It can also be replaced by int. After replacing the changed signature would look like
static int Main(string[] args)
{
        return 0;
}
I have given my best to explain all. Have any query or problem leave it in the comment box.
Happy coding ;)

Labels: , ,