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

前端 未结 10 1267
梦毁少年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条回答
  •  萌比男神i
    2021-02-06 21:28

    public and private are the access specifiers.

    we use,

     public static void Main()
    

    because to execute the program, you need to call your class in which this Main() method is present, for that you need your Main() method to be public otherwise it will not be accessible outside the class.

    And the reason why it is static is, because, it needs to be accessed without creating any objects of that class .i.e. at class level.

提交回复
热议问题