hello world example

T

Tony Johansson

Hello!

Here I have a very easy hello world example.
This example works fine. I just wonder how can it work when I have
private on the Main method. I would think that the operating system would
not be able to
call this Main method when I have decared it as private. Normally this
private is only for class members as you know. The reason it work must be
because the operating system (CLR) is considered as a class member.
using System;

class Hello
{
private static void Main()
{
Console.WriteLine("Hello world");
}
}



//Tony
 
M

Marc Gravell

Of course, a *gif* of a hyperlink (without the url visible) possibly has to
count as the worst advertising ever...

And Tony: giving you the benefit of the doubt, this is nothing to do with
the OS - it's just that the assembly defines it's own start point, and the
runtime finds this acceptable regardless of visibility. Note that your class
"Hello" is actually "internal", not "public", so you have the runtime
invoking a private member on an internal class. It just isn't an issue. Your
assembly says Hello.Main is the entry-point, and thus it is.

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top