Introduction to C# - Chapter- 1

In this chapter we will learn.

1-  Basic structure of a C# program.
2-  What is a Namespace?
3-  Purpose of Main Method.

Sample Program

//Namespace Declaration.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)

        {
            //Write to console.
            Console.WriteLine("Welcome to Vepsh Technology");
        }
    }
}

Let’s go and create a demo console application with C#.

>> Now create a new project.


>> Than add console application.

With dotnet we can use a verity of programming language like C#, Visual Basic, Visual C++, F# and many more. Now we will choose our programming language C# and with dotnet you can create different type of applications. You can create console application, web application, windows application, office application, SharePoint application, Silverlight application etc. But we will be creating a console application.


Now, you can change project name, location and click to OK button.
So, this creates the c# console project.  Now we will be taking about solution explorer, toolbox, and properties box etc. in letter chapter.

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

        {
          

        }
    }
}

I want to make this program as simple as possible. Let’s leave basic required line of code with in this program and remove unwanted line of code.

using System;
class Program
{
    static void Main()

    {


    }
}

I want this program to print any message to console screen. Console is a command prompt window. To get Command prompt >> RUN>> type CMD on it>> OK. It will look like.


using System;
class Program
{
    static void Main()
    {
        Console.WriteLine("Welcome to Vepsh Technologies");
    }
}
using System : It is a namespace that contain some classes like console etc.
Console is a class that to read and write message from command prompt.
WriteLine is a method in console class. It is use to write something on command prompt.

Using System Declaration

The namespace declaration, using System, indicates that you are using the System namespace. A name space is use to organize your code and is collection of classes, interfaces, structs, enum and delegates.
About classes, interfaces, structs, enum and delegates etc. we will discuss in details in latter chapter.

Note: - Main method is the entry point into your applications.