Question

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!

Was it helpful?

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.

OTHER TIPS

Generally there is no need to use primary class (which contains entry-point method definition) outside the assembly and that's why it has internal access.

each project can have its own entry point, you can also specify entry points to tell a individual project to execute the other. and IAbstract is right You can modify with static, public, or private

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top