Code style rules

.NET code style analysis provides rules that aim to maintain consistent code style in your codebase. These rules have an "IDE" prefix in the rule ID. Most of the rules have associated options to customize the preferred style. The rules are organized into the following subcategories:

  • Language rules

    Rules that pertain to the C# or Visual Basic language. For example, you can specify rules that regard the use of var when defining variables, or whether expression-bodied members are preferred.

  • Unnecessary code rules

    Rules that pertain to unnecessary code that indicates a potential readability, maintainability, performance, or functional problem. For example, unreachable code within methods or unused private fields, properties, or methods is unnecessary code.

  • 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 rules that regard Allman braces, or whether spaces in control blocks are preferred.

  • Naming rules

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

  • Miscellaneous rules

    Rules that do not belong in other categories.


The following table list all the code style rules by ID and options, if any.

Rule ID Title Option
IDE0001 Simplify name
IDE0002 Simplify member access
IDE0003 Remove this or Me qualification dotnet_style_qualification_for_field
IDE0004 Remove unnecessary cast
IDE0005 Remove unnecessary import
IDE0007 Use var instead of explicit type csharp_style_var_for_built_in_types
IDE0008 Use explicit type instead of var csharp_style_var_for_built_in_types
IDE0009 Add this or Me qualification dotnet_style_qualification_for_field
IDE0010 Add missing cases to switch statement
IDE0011 Add braces csharp_prefer_braces
IDE0016 Use throw expression csharp_style_throw_expression
IDE0017 Use object initializers dotnet_style_object_initializer
IDE0018 Inline variable declaration csharp_style_inlined_variable_declaration
IDE0019 Use pattern matching to avoid as followed by a null check csharp_style_pattern_matching_over_as_with_null_check
IDE0020 Use pattern matching to avoid is check followed by a cast (with variable) csharp_style_pattern_matching_over_is_with_cast_check
IDE0021 Use expression body for constructors csharp_style_expression_bodied_constructors
IDE0022 Use expression body for methods csharp_style_expression_bodied_methods
IDE0023 Use expression body for conversion operators csharp_style_expression_bodied_operators
IDE0024 Use expression body for operators csharp_style_expression_bodied_operators
IDE0025 Use expression body for properties csharp_style_expression_bodied_properties
IDE0026 Use expression body for indexers csharp_style_expression_bodied_indexers
IDE0027 Use expression body for accessors csharp_style_expression_bodied_accessors
IDE0028 Use collection initializers dotnet_style_collection_initializer
IDE0029 Use coalesce expression (non-nullable types) dotnet_style_coalesce_expression
IDE0030 Use coalesce expression (nullable types) dotnet_style_coalesce_expression
IDE0031 Use null propagation dotnet_style_null_propagation
IDE0032 Use auto property dotnet_style_prefer_auto_properties
IDE0033 Use explicitly provided tuple name dotnet_style_explicit_tuple_names
IDE0034 Simplify default expression csharp_prefer_simple_default_expression
IDE0035 Remove unreachable code
IDE0036 Order modifiers csharp_preferred_modifier_order
IDE0037 Use inferred member name dotnet_style_prefer_inferred_tuple_names
IDE0038 Use pattern matching to avoid is check followed by a cast (without variable) csharp_style_pattern_matching_over_is_with_cast_check
IDE0039 Use local function instead of lambda csharp_style_pattern_local_over_anonymous_function
IDE0040 Add accessibility modifiers dotnet_style_require_accessibility_modifiers
IDE0041 Use is null check dotnet_style_prefer_is_null_check_over_reference_equality_method
IDE0042 Deconstruct variable declaration csharp_style_deconstructed_variable_declaration
IDE0044 Add readonly modifier dotnet_style_readonly_field
IDE0045 Use conditional expression for assignment dotnet_style_prefer_conditional_expression_over_assignment
IDE0046 Use conditional expression for return dotnet_style_prefer_conditional_expression_over_return
IDE0047 Remove unnecessary parentheses dotnet_style_parentheses_in_arithmetic_binary_operators
IDE0048 Add parentheses for clarity dotnet_style_parentheses_in_arithmetic_binary_operators
IDE0049 Use language keywords instead of framework type names for type references dotnet_style_predefined_type_for_locals_parameters_members
IDE0050 Convert anonymous type to tuple
IDE0051 Remove unused private member
IDE0052 Remove unread private member
IDE0053 Use expression body for lambdas csharp_style_expression_bodied_lambdas
IDE0054 Use compound assignment dotnet_style_prefer_compound_assignment
IDE0055 Fix formatting
IDE0056 Use index operator csharp_style_prefer_index_operator
IDE0057 Use range operator csharp_style_prefer_range_operator
IDE0058 Remove unused expression value csharp_style_unused_value_expression_statement_preference
IDE0059 Remove unnecessary value assignment csharp_style_unused_value_assignment_preference
IDE0060 Remove unused parameter dotnet_code_quality_unused_parameters
IDE0061 Use expression body for local functions csharp_style_expression_bodied_local_functions
IDE0062 Make local function static csharp_prefer_static_local_function
IDE0063 Use simple using statement csharp_prefer_simple_using_statement
IDE0064 Make struct fields writable
IDE0065 using directive placement csharp_using_directive_placement
IDE0066 Use switch expression csharp_style_prefer_switch_expression
IDE0070 Use System.HashCode.Combine
IDE0071 Simplify interpolation dotnet_style_prefer_simplified_interpolation
IDE0072 Add missing cases to switch expression
IDE0073 Use file header file_header_template
IDE0074 Use coalesce compound assignment dotnet_style_prefer_compound_assignment
IDE0075 Simplify conditional expression dotnet_style_prefer_simplified_boolean_expressions
IDE0076 Remove invalid global SuppressMessageAttribute
IDE0077 Avoid legacy format target in global SuppressMessageAttribute
IDE0078 Use pattern matching csharp_style_prefer_pattern_matching
IDE0079 Remove unnecessary suppression dotnet_remove_unnecessary_suppression_exclusions
IDE0080 Remove unnecessary suppression operator
IDE0081 Remove ByVal
IDE0082 Convert typeof to nameof
IDE0083 Use pattern matching (not operator) csharp_style_prefer_not_pattern
IDE0084 Use pattern matching (IsNot operator) visual_basic_style_prefer_isnot_expression
IDE0090 Simplify new expression csharp_style_implicit_object_creation_when_type_is_apparent
IDE0100 Remove unnecessary equality operator
IDE0110 Remove unnecessary discard
IDE0140 Simplify object creation visual_basic_style_prefer_simplified_object_creation
IDE1005 Use conditional delegate call csharp_style_conditional_delegate_call
IDE1006 Naming styles


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

Item Description
Rule ID The unique identifier for the rule. The rule ID is used for configuring rule severity and suppressing warnings in the code file.
Title The title for the rule.
Category The category for the rule.
Subcategory The sub-category for the rule, such as Language rules, Formatting rules or Naming rules.
Applicable languages Applicable .NET languages (C# or Visual Basic), along with the minimum language version, if applicable.
Introduced version Version of the .NET SDK or Visual Studio when the rule was first introduced.

For each option for the rule, following information is provided.

Item Description
Option name The code style option name for the rule, if any. Options for customizing style are specified in an EditorConfig file.
Option values The code style option values for the rule option, if any.
Default option value Default code style option value for the rule option, if any.
Examples Examples for the code style corresponding to the option.

See also