S
Sean Dockery
I am a Java veteran who has just started learning C# with Tom Archer's
Inside C# 2nd Ed.
In the first chapter, there is a typical Hello, World! application that
looks like this...
namespace InsideCSharp
{
class HelloWorldConsoleApp
{
static void Main()
{
System.Console.WriteLine("Hello, World!");
}
}
}
(It was trivial to compile the HelloWorldConsole.cs file with csc and run it
directly as an Windows executable.)
The chapter describes how an application must contain a single public static
Main method as an entry point into the application. It goes on to describe
how a .NET application is really MSIL embedded inside a Windows PE, where
the MSIL is compiled and executed by a JIT compiler.
From what I have read in passing so far, the default visibility of a method
in a class in C# is private. So, it seems contrary to me that the sample
code with a Main method carrying default (private) visibility can be run
from outside the class. Furthermore, I tried explicitly adding the private
modifier to the Main method signature, and it continued to run without
issue.
Can anyone help me discover where my understanding of method visibility in
C# is breaking down?
Thanks.
Inside C# 2nd Ed.
In the first chapter, there is a typical Hello, World! application that
looks like this...
namespace InsideCSharp
{
class HelloWorldConsoleApp
{
static void Main()
{
System.Console.WriteLine("Hello, World!");
}
}
}
(It was trivial to compile the HelloWorldConsole.cs file with csc and run it
directly as an Windows executable.)
The chapter describes how an application must contain a single public static
Main method as an entry point into the application. It goes on to describe
how a .NET application is really MSIL embedded inside a Windows PE, where
the MSIL is compiled and executed by a JIT compiler.
From what I have read in passing so far, the default visibility of a method
in a class in C# is private. So, it seems contrary to me that the sample
code with a Main method carrying default (private) visibility can be run
from outside the class. Furthermore, I tried explicitly adding the private
modifier to the Main method signature, and it continued to run without
issue.
Can anyone help me discover where my understanding of method visibility in
C# is breaking down?
Thanks.