background image

public static void Main()

<< First C#.NET Program | compilation of the HelloWorld >>
<< First C#.NET Program | compilation of the HelloWorld >>
The lines in the program that starts with a // and /*....*/ (comment blocks) are comment
entries like in other programming languages which are excluded in the compilation
process. For C or C++ programmers the C# style of coding sounds great because it
almost follows the same style.

namespace HelloWorldSample - The keyword "namespace" is new to some
programmers who are not familiar with C++.

`namespace' ­ a keyword in .NET is used to avoid name collisions i.e. For example, you
develop a library which has a class named "File" and you use some other library which
also has a class named "File", in those cases there are chances of name collision. To
avoid this you can give a namespace name for your class, which should be meaningful. It
is always better to follow the syntax (MS Recommended) given below while giving
names for your namespaces

CompanyName
.TechnologyName

However the hierarchy can be extended based on the implementation of the classes in the
library.

public class HelloWorld - This is the class declaration in C#.NET; the interesting thing
for C++ or Java developers is that they can apply the OOPS concepts that are supported
by C#.NET . The class always ends with an "End Class".
`public' - is the modifier to determine the scope of the class (for other modifiers refer
.NET framework SDK documentation or later parts of this tutorial). HelloWorld is the
class name given for the class. Consumers of the class will be accessing through this
name only.

public static void Main () - This is called as the entry point function because the runtime
after loading your applications searches for an entry point from which the actual
execution starts. C/C++ programmers will find this method very familiar (VB
Programmers remember Sub Main). All Applications (exe) must have a definition for the
Main Method. Try removing the Main method from your application and the compiler
will complain that "No Start Point Defined". This means that the Main Method is the
starting point of any application, in other words When you execute your Application
"Main" method is called first automatically.

'public'
- This is the Access modifier for the Method. Since the Main method should be
accessible to everyone in order for the .NET Runtime to be able to call it automatically it
is always defined as public.

'static'
- indicates that the method is a Class Method. Hence it can be called without
making an instance of the class first.