liveBook · Manning

Top-level statement

As explained in ASP.NET Core in Action, 3e

A top-level statement is a C# statement written directly in a source file without an explicit containing class or Main method.

A top-level statement is C# code written directly in a source file without an explicit Program class or Main method. The compiler generates the entry point for you, making startup code shorter and easier to read. section 3.6

A minimal application

Console.WriteLine("Hello World!"); writes the application body directly in the file. The args variable is also available for command-line arguments, even though it is not declared explicitly. section 3.6

Listing 3.3 The default Program.cs file that configures and runs a WebApplication
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);  #1
WebApplication app = builder.Build();                                #2
 
app.MapGet("/", () => "Hello World!");                               #3
 
app.Run();                                                           #4

The default ASP.NET Core Program.cs uses top-level statements to create a WebApplicationBuilder, build the application, map a route, and start the server. section 3.6

How ASP.NET Core in Action, 3e covers it

How deep it goes
Defines generated Main, implicit args, and ASP.NET Core startup, but defers detailed limitations and customization.
Examples
Uses Hello World output, command-line argument iteration, and a default WebApplication route.
What it assumes
Assumes basic C# statements and introduces the distinction between generated and explicit Main methods.
What you can do after
Build a concise C# entry point and configure a basic ASP.NET Core application without writing Main explicitly.
How it connects
Connects the entry point with Main methods, implicit using statements, WebApplication, routing, and Kestrel.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ASP.NET Core in Action, 3e. The section links point to the parts of the book it draws on.