Minggu, 15 September 2013

Introduction to C# : Console Application Tutorial

In this tutorial we will learn basic structure of the c# program . A structure can hold multiple things such as namespaces , main method ,classes etc.
The basic structure of the c# program is

using System;
//import namespaces here

namespace ConsoleApplication4
{
    //create new namespace her also a namespace can contain sub namespace,classes,delegates etc
    class Program
    {
        //class start here . A class can hold data member and member function.  
        static void Main(string[] args)
        {
        }
    }
}


If you want to create a new c# application in visual studio then follow some steps for creating C# console application.
Step-1: Open visual studio
Step-2: Select file->new->project
Step-3: New Window will open , In Left pane you can select your language and right pane you can select application(console application)
Step-4: After selection (left pane-->VB and right pane -->Console application)
Step-5: now at time you can design your first c# application

If you want to write and read something like "hello world" on/from console window  then you should use Console class. This class provide static method for reading and writing . lets take an example if you want to write something on console window then use

Console.WriteLine("hello world");

Similarly if you want to read something from keyboard then use
  string n = Console.ReadLine();

  here is the complete code.
using System;
//import nameapces here

namespace ConsoleApplication4
{
    //create new namespace her also a namespace can contain sub namespace,classes,delegates etc
    class Program
    {
        //class start here . A class can hold data member and member function.
        static void Main(string[] args)
        {
        Console.WriteLine("hello world");
         string n = Console.ReadLine();
         Console.ReadKey();
        }
    }
}

 here is the first line define the declaration of the namespace.
 what is a namespace : The namespace is used to organize your code and is a collection of classes, interface, structs, enums and delegates.
 Main method: main method is the entry point into your application.
Output
Introduction to C# : Console Application Tutorial


Tidak ada komentar:

Posting Komentar