From 3f8422e22ed831189eca4eb1bafb9bc18ce0f5a9 Mon Sep 17 00:00:00 2001 From: Tim Deschryver <28659384+timdeschryver@users.noreply.github.com> Date: Thu, 29 Feb 2024 17:33:48 +0100 Subject: [PATCH] define top-level statements (#39742) --- .../fundamentals/program-structure/top-level-statements.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/csharp/fundamentals/program-structure/top-level-statements.md b/docs/csharp/fundamentals/program-structure/top-level-statements.md index 774b04c02b778..3d2e8834202aa 100644 --- a/docs/csharp/fundamentals/program-structure/top-level-statements.md +++ b/docs/csharp/fundamentals/program-structure/top-level-statements.md @@ -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: