Movatterモバイル変換


[0]ホーム

URL:


Skip to main content

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Download Microsoft EdgeMore info about Internet Explorer and Microsoft Edge
Table of contentsExit editor mode

Code-style rules

Feedback

In this article

.NET code-style analysis provides rules that aim to maintain consistentstyle in your codebase. These rules have an "IDE" prefix in the rule ID.

The code-style rules are organized into the following subcategories:

  • Language and unnecessary code rules

    Rules that pertain to the C# or Visual Basic language. For example, you can specify rules that regard the use ofvar when defining variables, or whether expression-bodied members are preferred. This category also includes rules that find unnecessary code, for example, unreachable code within methods or unused private fields, properties, or methods.

  • Formatting rules

    Rules that pertain to the layout and structure of your code in order to make it easier to read. For example, you can specify a formatting option that defines whether spaces in control blocks are preferred or not.

  • Naming rules

    Rules that pertain to the naming of code elements. For example, you can specify thatasync method names must have an "Async" suffix.

  • Miscellaneous rules

    Rules that do not belong in other categories.

Index

The following table list all the code-style rules by ID andoptions, if any.

Rule IDTitleOption
IDE0001Simplify name
IDE0002Simplify member access
IDE0003Removethis orMe qualificationdotnet_style_qualification_for_field
dotnet_style_qualification_for_property
dotnet_style_qualification_for_method
dotnet_style_qualification_for_event
IDE0004Remove unnecessary cast
IDE0005Remove unnecessary import
IDE0007Usevar instead of explicit typecsharp_style_var_for_built_in_types
csharp_style_var_when_type_is_apparent
csharp_style_var_elsewhere
IDE0008Use explicit type instead ofvarcsharp_style_var_for_built_in_types
csharp_style_var_when_type_is_apparent
csharp_style_var_elsewhere
IDE0009Addthis orMe qualificationdotnet_style_qualification_for_field
dotnet_style_qualification_for_property
dotnet_style_qualification_for_method
dotnet_style_qualification_for_event
IDE0010Add missing cases to switch statement
IDE0011Add bracescsharp_prefer_braces
IDE0016Use throw expressioncsharp_style_throw_expression
IDE0017Use object initializersdotnet_style_object_initializer
IDE0018Inline variable declarationcsharp_style_inlined_variable_declaration
IDE0019Use pattern matching to avoidas followed by anull checkcsharp_style_pattern_matching_over_as_with_null_check
IDE0020Use pattern matching to avoidis check followed by a cast (with variable)csharp_style_pattern_matching_over_is_with_cast_check
IDE0021Use expression body for constructorscsharp_style_expression_bodied_constructors
IDE0022Use expression body for methodscsharp_style_expression_bodied_methods
IDE0023Use expression body for conversion operatorscsharp_style_expression_bodied_operators
IDE0024Use expression body for operatorscsharp_style_expression_bodied_operators
IDE0025Use expression body for propertiescsharp_style_expression_bodied_properties
IDE0026Use expression body for indexerscsharp_style_expression_bodied_indexers
IDE0027Use expression body for accessorscsharp_style_expression_bodied_accessors
IDE0028Use collection initializersdotnet_style_collection_initializer
dotnet_style_prefer_collection_expression
IDE0029Null check can be simplifieddotnet_style_coalesce_expression
IDE0030Null check can be simplifieddotnet_style_coalesce_expression
IDE0031Use null propagationdotnet_style_null_propagation
IDE0032Use auto propertydotnet_style_prefer_auto_properties
IDE0033Use explicitly provided tuple namedotnet_style_explicit_tuple_names
IDE0034Simplifydefault expressioncsharp_prefer_simple_default_expression
IDE0035Remove unreachable code
IDE0036Order modifierscsharp_preferred_modifier_order
visual_basic_preferred_modifier_order
IDE0037Use inferred member namedotnet_style_prefer_inferred_tuple_names
dotnet_style_prefer_inferred_anonymous_type_member_names
IDE0038Use pattern matching to avoidis check followed by a cast (without variable)csharp_style_pattern_matching_over_is_with_cast_check
IDE0039Use local function instead of lambdacsharp_style_prefer_local_over_anonymous_function
IDE0040Add accessibility modifiersdotnet_style_require_accessibility_modifiers
IDE0041Use is null checkdotnet_style_prefer_is_null_check_over_reference_equality_method
IDE0042Deconstruct variable declarationcsharp_style_deconstructed_variable_declaration
IDE0044Add readonly modifierdotnet_style_readonly_field
IDE0045Use conditional expression for assignmentdotnet_style_prefer_conditional_expression_over_assignment
IDE0046Use conditional expression for returndotnet_style_prefer_conditional_expression_over_return
IDE0047Remove unnecessary parenthesesdotnet_style_parentheses_in_arithmetic_binary_operators
dotnet_style_parentheses_in_relational_binary_operators
dotnet_style_parentheses_in_other_binary_operators
dotnet_style_parentheses_in_other_operators
IDE0048Add parentheses for claritydotnet_style_parentheses_in_arithmetic_binary_operators
dotnet_style_parentheses_in_relational_binary_operators
dotnet_style_parentheses_in_other_binary_operators
dotnet_style_parentheses_in_other_operators
IDE0049Use language keywords instead of framework type names for type referencesdotnet_style_predefined_type_for_locals_parameters_members
dotnet_style_predefined_type_for_member_access
IDE0050Convert anonymous type to tuple
IDE0051Remove unused private member
IDE0052Remove unread private member
IDE0053Use expression body for lambdascsharp_style_expression_bodied_lambdas
IDE0054Use compound assignmentdotnet_style_prefer_compound_assignment
IDE0055Fix formatting(Too many to list here. See.NET formatting options andC# formatting options.)
IDE0056Use index operatorcsharp_style_prefer_index_operator
IDE0057Use range operatorcsharp_style_prefer_range_operator
IDE0058Remove unused expression valuecsharp_style_unused_value_expression_statement_preference
visual_basic_style_unused_value_expression_statement_preference
IDE0059Remove unnecessary value assignmentcsharp_style_unused_value_assignment_preference
visual_basic_style_unused_value_assignment_preference
IDE0060Remove unused parameterdotnet_code_quality_unused_parameters
IDE0061Use expression body for local functionscsharp_style_expression_bodied_local_functions
IDE0062Make local functionstaticcsharp_prefer_static_local_function
IDE0063Use simpleusing statementcsharp_prefer_simple_using_statement
IDE0064Make struct fields writable
IDE0065using directive placementcsharp_using_directive_placement
IDE0066Use switch expressioncsharp_style_prefer_switch_expression
IDE0070UseSystem.HashCode.Combine
IDE0071Simplify interpolationdotnet_style_prefer_simplified_interpolation
IDE0072Add missing cases to switch expression
IDE0073Use file headerfile_header_template
IDE0074Use coalesce compound assignmentdotnet_style_prefer_compound_assignment
IDE0075Simplify conditional expressiondotnet_style_prefer_simplified_boolean_expressions
IDE0076Remove invalid globalSuppressMessageAttribute
IDE0077Avoid legacy format target in globalSuppressMessageAttribute
IDE0078Use pattern matchingcsharp_style_prefer_pattern_matching
IDE0079Remove unnecessary suppressiondotnet_remove_unnecessary_suppression_exclusions
IDE0080Remove unnecessary suppression operator
IDE0081RemoveByVal
IDE0082Converttypeof tonameof
IDE0083Use pattern matching (not operator)csharp_style_prefer_not_pattern
IDE0084Use pattern matching (IsNot operator)visual_basic_style_prefer_isnot_expression
IDE0090Simplifynew expressioncsharp_style_implicit_object_creation_when_type_is_apparent
IDE0100Remove unnecessary equality operator
IDE0110Remove unnecessary discard
IDE0120Simplify LINQ expression
IDE0121Simplify LINQ type check and cast
IDE0130Namespace does not match folder structuredotnet_style_namespace_match_folder
IDE0140Simplify object creationvisual_basic_style_prefer_simplified_object_creation
IDE0150Prefernull check over type checkcsharp_style_prefer_null_check_over_type_check
IDE0160Use block-scoped namespacecsharp_style_namespace_declarations
IDE0161Use file-scoped namespacecsharp_style_namespace_declarations
IDE0170Simplify property patterncsharp_style_prefer_extended_property_pattern
IDE0180Use tuple to swap valuescsharp_style_prefer_tuple_swap
IDE0200Remove unnecessary lambda expressioncsharp_style_prefer_method_group_conversion
IDE0210Convert to top-level statementscsharp_style_prefer_top_level_statements
IDE0211Convert to 'Program.Main' style programcsharp_style_prefer_top_level_statements
IDE0220Add explicit cast in foreach loopdotnet_style_prefer_foreach_explicit_cast_in_source
IDE0230Use UTF-8 string literalcsharp_style_prefer_utf8_string_literals
IDE0240Nullable directive is redundant
IDE0241Nullable directive is unnecessary
IDE0250Struct can be made 'readonly'csharp_style_prefer_readonly_struct
IDE0251Member can be made 'readonly'csharp_style_prefer_readonly_struct_member
IDE0260Use pattern matchingcsharp_style_pattern_matching_over_as_with_null_check
IDE0270Null check can be simplifieddotnet_style_coalesce_expression
IDE0280Usenameof
IDE0290Use primary constructorcsharp_style_prefer_primary_constructors
IDE0300Use collection expression for arraydotnet_style_prefer_collection_expression
IDE0301Use collection expression for emptydotnet_style_prefer_collection_expression
IDE0302Use collection expression for stackallocdotnet_style_prefer_collection_expression
IDE0303Use collection expression forCreate()dotnet_style_prefer_collection_expression
IDE0304Use collection expression for builderdotnet_style_prefer_collection_expression
IDE0305Use collection expression for fluentdotnet_style_prefer_collection_expression
IDE0306Use collection expression for newdotnet_style_prefer_collection_expression
IDE0320Make anonymous functionstaticcsharp_prefer_static_anonymous_function
IDE0330Prefer 'System.Threading.Lock'csharp_prefer_system_threading_lock
IDE0340Use unbound generic typecsharp_style_prefer_unbound_generic_type_in_nameof
IDE0350Use implicitly typed lambdacsharp_style_prefer_implicitly_typed_lambda_expression
IDE0360Simplify property accessorcsharp_style_prefer_simple_property_accessors
IDE0370Remove unnecessary suppression
IDE0380Remove unnecessary 'unsafe' modifier
IDE1005Use conditional delegate callcsharp_style_conditional_delegate_call
IDE1006Naming styles
IDE2000Avoid multiple blank linesdotnet_style_allow_multiple_blank_lines_experimental
IDE2001Embedded statements must be on their own linecsharp_style_allow_embedded_statements_on_same_line_experimental
IDE2002Consecutive braces must not have blank line between themcsharp_style_allow_blank_lines_between_consecutive_braces_experimental
IDE2003Blank line required between block and subsequent statementdotnet_style_allow_statement_immediately_after_block_experimental
IDE2004Blank line not allowed after constructor initializer coloncsharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental
IDE2005Blank line not allowed after conditional expression tokencsharp_style_allow_blank_line_after_token_in_conditional_expression_experimental
IDE2006Blank line not allowed after arrow expression clause tokencsharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental
IDE3000Implement with Copilot

†These rules are experimental and subject to change or removal.

Note

There are some rules that only surface in the Visual Studio IDE, and these regard JSON and regular expression pattern strings. For more information, seeJSON001,JSON002, andRE0001.

Legend

The following table shows the type of information that's provided for each rule in the reference documentation.

ItemDescription
Rule IDThe unique identifier for the rule. Used for configuring rule severity and suppressing warnings in the code file.
TitleThe title for the rule.
CategoryThe category for the rule.
SubcategoryThe subcategory for the rule, such as Language rules, Formatting rules, or Naming rules.
Applicable languagesApplicable .NET languages (C# or Visual Basic), along with the minimum language version, if applicable.
Introduced versionVersion of the .NET SDK or Visual Studio when the rule was first introduced.
OptionsAny available options for the rule.

See also

Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, seeour contributor guide.

Feedback

Was this page helpful?

YesNoNo

Need help with this topic?

Want to try using Ask Learn to clarify or guide you through this topic?

Suggest a fix?

  • Last updated on

In this article

Was this page helpful?

YesNo
NoNeed help with this topic?

Want to try using Ask Learn to clarify or guide you through this topic?

Suggest a fix?