Why is Main method private?

前端 未结 4 1331
抹茶落季
抹茶落季 2020-11-29 06:28

New console project template creates a Main method like this:

class Program
{
    static void Main(string[] args)
    {
    }
}

Why is it th

4条回答
  •  借酒劲吻你
    2020-11-29 06:48

    The Main method shouldn't need to be called by anyone.

    It is actually marked as the entry point for execution in the EXE itself, and therefore has no outside callers by default.

    If you WANT, you can open it up to be called by marking public, e.g. if you are turning a console app into an API.

提交回复
热议问题