All rules
IDE0210Language rules (code-block preferences)
Convert to top-level statements
Convert to top-level statements
Microsoft docsDescription
This rule flags the use of a Main method entry point in a project that could be converted to top-level statements instead. A candidate method must meet the following requirements:
- Is
static. - Is named
Main. - Has a method body.
- Has no type parameters.
- Is contained in a type that's not
public, doesn't derive from another type or implement an interface, isn't a nested type, and has no attributes or documentation comments.
Example
// Code with violations.
internal class Program
{
private static void Main(string[] args)
{
Console.WriteLine("Hello world.");
}
}
// Fixed code.
Console.WriteLine("Hello world.");Configurable options
Vote for the value each option should take in the generated .editorconfig.
csharp_style_prefer_top_level_statements default:
trueYour vote
Group results
0 yes 0 no
ConsensusNone (disabled)
Severity preference (yes voters)
Suggestion0
Warning0
Error0