What is the difference between public static void Main() and private static void Main() in a C# console application?

前端 未结 10 1160
梦毁少年i
梦毁少年i 2021-02-06 20:32

What is the difference between

public static void Main()

and

private static void Main()

in a C# console appli

10条回答
  •  醉酒成梦
    2021-02-06 21:31

    To act as the start point in your application, the Main method is not required to be public.

    If you did decide to make it public, it would be possible for it to be called from other classes or assemblies. Typically you will not need to do this, so you can keep it private.

    One possible use case for making it public would be to allow automated tests to invoke it.

提交回复
热议问题