Search code examples
c#access-modifiersentry-pointmodifier

C# entry point class modifier


My question is about entry point in a C# program. I'm using VS 2010 and it automatically generates Program.cs file with program class:

class Program 
{
   ...
   static void Main(...)
   ...
}

My question is why this class is by default internal? Why is not public? An if there are situations to chose one ore another modifier, how to understand which one I need for this basic class?

P.S. I am a Java programmer actually and now trying to learn C# but some details are missing from books. Thanks!


Solution

  • The assembly generated is an EXE. You wouldn't normally add a reference to an EXE assembly, which means nothing other than classes within the EXE would access Program--which means internal perfectly describes how it would be used. Prior to .NET 2.0 you actually couldn't refernce and EXE, so Program being public is wrong because it can be accessed as anything other than internal.