Convert to 'Program.Main' style program (IDE0211)
Property | Value |
---|---|
Rule ID | IDE0211 |
Title | Convert to 'Program.Main' style program |
Category | Style |
Subcategory | Language rules (code-block preferences) |
Applicable languages | C# 9+ |
Options | csharp_style_prefer_top_level_statements |
Overview
This rule flags the use of top-level statements instead of a Main
method entry point in a project.
Options
Options specify the behavior that you want the rule to enforce. For information about configuring options, see Option format.
csharp_style_prefer_top_level_statements
Property | Value | Description |
---|---|---|
Option name | csharp_style_prefer_top_level_statements | |
Option values | true |
Disables the rule. |
false |
Prefer Program.Main style program. |
|
Default option value | true |
Example
// Code with violations (entire file).
Console.WriteLine("Hello world.");
// Fixed code.
internal class Program
{
private static void Main(string[] args)
{
Console.WriteLine("Hello world.");
}
}
Suppress a warning
If you want to suppress only a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.
#pragma warning disable IDE0211
// The code that's violating the rule is on this line.
#pragma warning restore IDE0211
To disable the rule for a file, folder, or project, set its severity to none
in the configuration file.
[*.{cs,vb}]
dotnet_diagnostic.IDE0211.severity = none
To disable all of the code-style rules, set the severity for the category Style
to none
in the configuration file.
[*.{cs,vb}]
dotnet_analyzer_diagnostic.category-Style.severity = none
For more information, see How to suppress code analysis warnings.
See also
Σχόλια
https://aka.ms/ContentUserFeedback.
Σύντομα διαθέσιμα: Καθ' όλη τη διάρκεια του 2024 θα καταργήσουμε σταδιακά τα ζητήματα GitHub ως μηχανισμό ανάδρασης για το περιεχόμενο και θα το αντικαταστήσουμε με ένα νέο σύστημα ανάδρασης. Για περισσότερες πληροφορίες, ανατρέξτε στο θέμα:Υποβολή και προβολή σχολίων για