Anatomy of a Program
Starting a Program
A program in C# is defined with a class containing a Main
method. The code sample below is the starting point for a console application.
C#
using System;
namespace ADEV.BIT.RRC
{
internal class Program
{
static void Main(string args[])
{
}
}
}
- Line 1: Using statements allow you to import modules defined within other namespaces. The
System
namespace contains the core functionality of C#, including theConsole
class. - Line 3: Declares the namespace the module is compiled to. The namespace is an identifier made up by you as a way of organizing related modules and types. Using dot notation, you can declare sub-namespaces.
- Line 5: Declares a class with the identifier
Program
. It is customary in C# to declare your program class asProgram
. - Line 7: Declares the
Main
method. TheMain
method is invoked automatically when a program is executed.
Note
The curly braces ('{' and '}') indicate a block of code. Statements intended to be part of a class or method must be written within the appropriate block.