Skip to content

Commit

Permalink
define top-level statements (dotnet#39742)
Browse files Browse the repository at this point in the history
  • Loading branch information
timdeschryver authored Feb 29, 2024
1 parent ed11014 commit 3f8422e
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ helpviewer_keywords:
---
# Top-level statements - programs without `Main` methods

You don't have to explicitly include a `Main` method in a console application project. Instead, you can use the *top-level statements* feature to minimize the code you have to write. In this case, the compiler generates a `Program` class with an entry point method for the application. The name of the generated method isn't `Main`, it's an implementation detail that your code can't reference directly.
You don't have to explicitly include a `Main` method in a console application project. Instead, you can use the *top-level statements* feature to minimize the code you have to write.

Top-level statements allows you to write executable code directly at the root of a file, eliminating the need for wrapping your code in a class or method.
This means you can create programs without the ceremony of a `Program` class and a `Main` method.
In this case, the compiler generates a `Program` class with an entry point method for the application. The name of the generated method isn't `Main`, it's an implementation detail that your code can't reference directly.

Here's a *Program.cs* file that is a complete C# program in C# 10:

Expand Down

0 comments on commit 3f8422e

Please sign in to comment.