locked
Whats the default access specifier of main function in c#. RRS feed

Answers

  • Hi Jvim,

    The default access modifier for members, i.e. for fields, methods, propertoes, etc, is private.

    Hence by default, the main method is private. For CLR(Common Language Runtime), everthing is public.

    The signature of main method is static void main(). Since the main method is static, it will be executed even before the creation of any object. That is, the execution of any program will start from the main method.

    Non-static methods are invoked using an object of the class in which the method has been defined,

    • Proposed as answer by Deepak Narayan Monday, July 9, 2018 7:14 AM
    • Marked as answer by jvim Monday, July 9, 2018 8:08 AM
    Monday, July 9, 2018 7:13 AM

All replies

  • In Visual Studio it is private but it is not always. In this article it is explained why method is private.

    https://www.codeproject.com/Articles/479467/Main-Method-in-Csharp

    Monday, July 9, 2018 6:55 AM
  • Hi Jvim,

    The default access modifier for members, i.e. for fields, methods, propertoes, etc, is private.

    Hence by default, the main method is private. For CLR(Common Language Runtime), everthing is public.

    The signature of main method is static void main(). Since the main method is static, it will be executed even before the creation of any object. That is, the execution of any program will start from the main method.

    Non-static methods are invoked using an object of the class in which the method has been defined,

    • Proposed as answer by Deepak Narayan Monday, July 9, 2018 7:14 AM
    • Marked as answer by jvim Monday, July 9, 2018 8:08 AM
    Monday, July 9, 2018 7:13 AM
  • https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/main-and-command-args/
    Tuesday, July 10, 2018 1:33 PM