-
Notifications
You must be signed in to change notification settings - Fork 6k
Description
It's also an error if you combine top-level statements with a declared program entry point method, typically a Main method. In a sense, you can think that one file contains the statements that would normally be in the Main method of a Program class.
The compiler will only issue an error if the type name is Program
. You could, for example, have
class HelloWorld
{
static void Main() {}
}
This will result in a warning, but not an error.
Consider the following rewording:
It's warning if you combine top-level statements with a declared program entry point method, typically a Main method. In a sense, you can think that one file contains the statements that would normally be in the Main method of a
Program
class. For this reason, you cannot, in fact, declare your ownProgram
class - as this is the name given to the class generated by the C# compiler for top-level statements.
Document Details
⚠ Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.
- ID: d75fd4d4-6fc5-62b9-95be-69c7e20ff094
- Version Independent ID: f4efd3be-0877-c8f9-32e0-58638759b46b
- Content: What's new in C# 9.0 - C# Guide
- Content Source: docs/csharp/whats-new/csharp-9.md
- Product: dotnet-csharp
- Technology: csharp-whats-new
- GitHub Login: @BillWagner
- Microsoft Alias: wiwagn