Search code examples
c#c++oopprogram-entry-point

why main method in c# is always placed inside the class but not in c++


Why we put main() method always inside the class in C# while in c++ it always placed outside of the class.


Solution

  • For historical reasons. C++ evolved from C, which had a global main() function. C# is much younger and was designed from scratch. One of the design features of C# is the absence of global functions, so the main function has to belong to a class.