All Type Coding

Search Here

How to write a program in c#

First of all Open visual studio go to-> file ->new ->project



after that select Console Application like  above image
We will learn the basic structure of a c# program. C# allows us to write programs like Console Bases Applications as well as Windows Based Applications Now I wrote a code for simple program in c# copy below code and paste in your project

using System;

    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("--- WELCOME TO ALLTYPECODING ---");
            Console.ReadKey();
        }

    }

When you run this C# program you will get 
"--- WELCOME TO ALLTYPECODING ---" in the console and the system wait for the input from the user. Console.ReadKey() is waiting for user input. 

Output :



Here using System is a namespace - The namespace declaration,using System, indicates that you are using the System namespace. If  you omit the using System, declaration, then you have to use the fully qualified name of the Console class like below.

 class Program
    {
        static void Main(string[] args)
        {
       System.Console.WriteLine("--- WELCOME TO ALLTYPECODING ---");
       System.Console.ReadKey();
        }
    }

 A namespace is used to organize your code and is collection of classes, interfaces, structs, enums and delegates.
The Main() method - It is the entry point into your application.

No comments :

Post a Comment