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

前端 未结 10 1163
梦毁少年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:15

    The difference between both is the only difference in public and private access modifiers because both are valid.It totally depends on the usage of application which one to use.

    If you want to initiate entry point by any external program, (ie use as API, for testing purpose) then you might need to make it public so it is accessible.

    public

    If you know there is no external usage for the application then it is better to make it private so no external application get access to it.

    private

提交回复
热议问题