Program Entry point in C#

More Examples

kamran.cs
class zzz
{
  public void Main()
  {
  }
}


Compiler Error
error CS5001: Program 'kamran.exe' does not have an entry point defined

The signature also includes modifiers like static etc. It just proves the importance of the function Main and the way it has been defined.

kamran.cs
class zzz {
  public static void Main()
  {
  }
}
class yyy
{
  public static void Main()
  {
  }
}


Compiler Error
kamran.cs(3,20): error CS0017: Program 'kamran.exe' has more than one entry point defined: 'zzz.Main()'
kamran.cs(3,20): error CS0017: Program 'kamran.exe' has more than one entry point defined: 'yyy.Main()'


The error proves the point that you cannot have two different classes, zzz and yyy, containing Main. Only one occurrence of Main is allowed. You always have only one chance of a lifetime. Ditto with Main.

kamran.cs
class zzz
{
  private static void Main()
  {
    System.Console.WriteLine("hell");
  }
}

Output
hell

The access modifiers are not included within the signature for Main. Even though Main is made private, it is considered as an entry point function, hence hell gets displayed. This function is unique and works as a special case.

You might also like...

Comments

About the author

Kamran Shakil Pakistan

I am 22 male. BS(Computer Science), MCSE, Brainbench certifed. Member of .NET Open source, Mono Project. E-author on various websites, including www.dotnetextreme.com, www.csharphelp.com and so...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“In order to understand recursion, one must first understand recursion.”