none
why in C# Main Method is static..?

    Question

  • why in C# Main Method is static..?

    In C++ static functions can access only static variables.

    who will invoke main() method in C++.

    Tuesday, June 01, 2010 10:47 AM

Answers

  • Static keyword is used so that that class cannot be instantiated.
    it means you cannot create any new instance of main. Only one copy of the Main() will be shared throughout the program.

    When a program is launched, no instances of any class are present in memory. As the Main method is static, it can be called without creating an object and can then assume control of the program. It is the Main method's task to create the objects that the program requires to function correctly.

     

    • Marked as answer by Sudhakar_M Tuesday, June 01, 2010 12:50 PM
    Tuesday, June 01, 2010 10:57 AM
  • why in C# Main Method is static..?

    In C++ static functions can access only static variables.

    who will invoke main() method in C++.


    It's the same in C# - static methods can only access static fields, properties, and methods.

    And since all .NET executables need an entry point method, and since C# does not support a global method (not in a class), the designers decided to default to a static Main method as the entry point method.

    When a .NET app is executed, the CLR automatically starts executing this entry point method pretty early in the app's lifetime.


    http://blog.voidnish.com
    • Marked as answer by Sudhakar_M Tuesday, June 01, 2010 12:50 PM
    Tuesday, June 01, 2010 10:56 AM
  • The static modifier means that it does not have to be instantiated to use it.

    Before a program runs there are technically no objects created yet, so the main method, which is the entry point for the application must be labeled static to tell the CLR that the method can be used without having first to create an instance of that class. Otherwise, it is the "Which came first, the chicken or the egg?" phenomenon.

    • Marked as answer by Sudhakar_M Tuesday, June 01, 2010 12:50 PM
    Tuesday, June 01, 2010 12:19 PM
  • static SomeFn() 

    means: this method is accessable without creating instance of class

    now Main mehtod in c# invokes by OS without object creating .

     c# is pure object oriented language and should obey the O.O rules so make his syntax at this form(static main);  

    • Marked as answer by Sudhakar_M Wednesday, June 02, 2010 4:25 AM
    Tuesday, June 01, 2010 2:26 PM

All replies

  • Tuesday, June 01, 2010 10:55 AM
  • why in C# Main Method is static..?

    In C++ static functions can access only static variables.

    who will invoke main() method in C++.


    It's the same in C# - static methods can only access static fields, properties, and methods.

    And since all .NET executables need an entry point method, and since C# does not support a global method (not in a class), the designers decided to default to a static Main method as the entry point method.

    When a .NET app is executed, the CLR automatically starts executing this entry point method pretty early in the app's lifetime.


    http://blog.voidnish.com
    • Marked as answer by Sudhakar_M Tuesday, June 01, 2010 12:50 PM
    Tuesday, June 01, 2010 10:56 AM
  • Static keyword is used so that that class cannot be instantiated.
    it means you cannot create any new instance of main. Only one copy of the Main() will be shared throughout the program.

    When a program is launched, no instances of any class are present in memory. As the Main method is static, it can be called without creating an object and can then assume control of the program. It is the Main method's task to create the objects that the program requires to function correctly.

     

    • Marked as answer by Sudhakar_M Tuesday, June 01, 2010 12:50 PM
    Tuesday, June 01, 2010 10:57 AM
  • The static modifier means that it does not have to be instantiated to use it.

    Before a program runs there are technically no objects created yet, so the main method, which is the entry point for the application must be labeled static to tell the CLR that the method can be used without having first to create an instance of that class. Otherwise, it is the "Which came first, the chicken or the egg?" phenomenon.

    • Marked as answer by Sudhakar_M Tuesday, June 01, 2010 12:50 PM
    Tuesday, June 01, 2010 12:19 PM
  • static SomeFn() 

    means: this method is accessable without creating instance of class

    now Main mehtod in c# invokes by OS without object creating .

     c# is pure object oriented language and should obey the O.O rules so make his syntax at this form(static main);  

    • Marked as answer by Sudhakar_M Wednesday, June 02, 2010 4:25 AM
    Tuesday, June 01, 2010 2:26 PM