I'm trying to create a program using OOP in C# with Visual Studio 2022. However normally when you create a class, for example in Java there is a main method that is used to run the program. But in C# and Visual Studio I don't have a main class all I see is:
When it's supposed to be this: Is there a reason for this?
CodePudding user response:
These are called top-level statements and is a relatively new language feature. The concept is explained well in the documentation: https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/tutorials/top-level-statements
CodePudding user response:
"Starting in C# 9, you can omit the Main method, and write C# statements as if they were in the Main method" https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/program-structure/main-command-line
CodePudding user response:
You created your project with a top-level statement. If you want to view the Main()
method, select "Do not use top-level statements" before creating the Visual Studio project.