Search Results

Wednesday, April 8, 2009

(1)The Anatomy Of a Simple C# Program

In C# it is not possible to create global functions or global points of data.Rather,all data members and methods must be contained within a type definition.

First make a Console Application Project in C#.
//**********************************************//
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
}
}
}
//**********************************************//
It will make a project as above.


You can update your Main() by adding some additional code in you Main() body
//**************************************************//
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
//Dispaly a simple Message to the User
Console.WriteLine("Hello World");
Console.WriteLine("C# World");

//wait for enter key to be presses before quit
Console.ReadLine();

}
}
}
//************************************************//

Formally speaking,the class that defines the Main() method is termed the "application object"

While it is possible for a single executable application to have more than one application object.

For the time being,simply understand that static members are scoped to the class level(rather than the object level) and can thus be created without the need to first create a new class instance.

//*********************************************************************************//

The keyword static allows Main( ) to be called before an object of its class has been created. This is necessary because Main( ) is called at program startup. The keyword void simply tells the compiler that Main( ) does not return a value. As you will see, methods can also return values.

No comments:

Post a Comment