Language conventions

Language conventions for EditorConfig in Visual Studio fall into two categories: those that apply to Visual Basic and C#, and those that are C# specific. Language conventions affect how various aspects of a programming language are used, for example, modifiers and parentheses.

Tip

  • To see the code examples in your preferred programming language, choose it using the language picker at the top-right corner of the browser window.

    Code language picker control

  • Use the In this article links to jump to different sections of the page.

Rule format

Rules for language conventions have the following general format:

option_name = value:severity

For each language convention, you specify a value that defines if or when to prefer the style. Many rules accept a value of true (prefer this style) or false (do not prefer this style). Other rules accept values such as when_on_single_line or never. The second part of the rule specifies the severity.

Note

Because language conventions are enforced by analyzers, you can also set their severity by using the default configuration syntax for analyzers. The syntax takes the form dotnet_diagnostic.<rule ID>.severity = <severity>, for example, dotnet_diagnostic.IDE0040.severity = silent. For more information, see Set rule severity in an EditorConfig file.

Severity levels

A language convention severity specifies the level at which to enforce that style. The following table lists the possible severity values and their effects:

Severity Effect
error When this style rule is violated, show a compiler error.
warning When this style rule is violated, show a compiler warning.
suggestion When this style rule is violated, show it to the user as a suggestion. Suggestions appear as three gray dots under the first two characters.
silent Do not show anything to the user when this rule is violated. Code generation features generate code in this style, however. Rules with silent severity participate in cleanup and appear in the Quick Actions and Refactorings menu.
none Do not show anything to the user when this rule is violated. Code generation features generate code in this style, however. Rules with none severity never appear in the Quick Actions and Refactorings menu. In most cases, this is considered "disabled" or "ignored".

Automatically configure code styles

Starting in Visual Studio 2019 version 16.3, you can configure code style rules from the Quick Actions light bulb menu after a style violation occurs.

To change the code style convention:

  1. Hover over the squiggle in the editor, and then open the light bulb menu that appears. Choose Configure or Suppress issues > Configure <rule ID> code style.

    Configure code style from light bulb menu in Visual Studio

  2. From there, choose one of the code style options.

    Configure code style setting

    Visual Studio adds or modifies the configuration setting in the EditorConfig file, as shown in the preview box.

To change the severity of the code style violation, follow the same steps, but choose Configure <rule ID> severity instead of Configure <rule ID> code style. For more information, see Automatically configure rule severity.

.NET code style settings

The style rules in this section are applicable to both C# and Visual Basic.

  • "This." and "Me." qualifiers
    • dotnet_style_qualification_for_field
    • dotnet_style_qualification_for_property
    • dotnet_style_qualification_for_method
    • dotnet_style_qualification_for_event
  • Language keywords instead of framework type names for type references
    • dotnet_style_predefined_type_for_locals_parameters_members
    • dotnet_style_predefined_type_for_member_access
  • Modifier preferences
    • dotnet_style_require_accessibility_modifiers
    • visual_basic_preferred_modifier_order
    • dotnet_style_readonly_field
  • Parentheses preferences
    • dotnet_style_parentheses_in_arithmetic_binary_operators
    • dotnet_style_parentheses_in_other_binary_operators
    • dotnet_style_parentheses_in_other_operators
    • dotnet_style_parentheses_in_relational_binary_operators
  • Expression-level preferences
    • dotnet_style_object_initializer
    • dotnet_style_collection_initializer
    • dotnet_style_explicit_tuple_names
    • dotnet_style_prefer_inferred_tuple_names
    • dotnet_style_prefer_inferred_anonymous_type_member_names
    • dotnet_style_prefer_auto_properties
    • dotnet_style_prefer_conditional_expression_over_assignment
    • dotnet_style_prefer_conditional_expression_over_return
    • dotnet_style_prefer_compound_assignment
  • "Null" checking preferences
    • dotnet_style_coalesce_expression
    • dotnet_style_null_propagation
    • dotnet_style_prefer_is_null_check_over_reference_equality_method

"This." and "Me." qualifiers

This style rule can be applied to fields, properties, methods, or events. A value of true means prefer the code symbol to be prefaced with this. in C# or Me. in Visual Basic. A value of false means prefer the code element not to be prefaced with this. or Me..

These rules could appear in an .editorconfig file as follows:

# CSharp and Visual Basic code style settings:
[*.{cs,vb}]
dotnet_style_qualification_for_field = false:suggestion
dotnet_style_qualification_for_property = false:suggestion
dotnet_style_qualification_for_method = false:suggestion
dotnet_style_qualification_for_event = false:suggestion

dotnet_style_qualification_for_field

Rule name dotnet_style_qualification_for_field
Rule ID IDE0003 and IDE0009
Applicable languages C# and Visual Basic
Values true - Prefer fields to be prefaced with this. in C# or Me. in Visual Basic

false - Prefer fields not to be prefaced with this. or Me.
Visual Studio default false:silent

Code examples:

// dotnet_style_qualification_for_field = true
this.capacity = 0;

// dotnet_style_qualification_for_field = false
capacity = 0;
' dotnet_style_qualification_for_field = true
Me.capacity = 0

' dotnet_style_qualification_for_field = false
capacity = 0

dotnet_style_qualification_for_property

Rule name dotnet_style_qualification_for_property
Rule ID IDE0003 and IDE0009
Applicable languages C# and Visual Basic
Values true - Prefer properties to be prefaced with this. in C# or Me. in Visual Basic

false - Prefer properties not to be prefaced with this. or Me.
Visual Studio default false:silent

Code examples:

// dotnet_style_qualification_for_property = true
this.ID = 0;

// dotnet_style_qualification_for_property = false
ID = 0;
' dotnet_style_qualification_for_property = true
Me.ID = 0

' dotnet_style_qualification_for_property = false
ID = 0

dotnet_style_qualification_for_method

Rule name dotnet_style_qualification_for_method
Rule ID IDE0003 and IDE0009
Applicable languages C# and Visual Basic
Values true - Prefer methods to be prefaced with this. in C# or Me. in Visual Basic.

false - Prefer methods not to be prefaced with this. or Me..
Visual Studio default false:silent

Code examples:

// dotnet_style_qualification_for_method = true
this.Display();

// dotnet_style_qualification_for_method = false
Display();
' dotnet_style_qualification_for_method = true
Me.Display()

' dotnet_style_qualification_for_method = false
Display()

dotnet_style_qualification_for_event

Rule name dotnet_style_qualification_for_event
Rule ID IDE0003 and IDE0009
Applicable languages C# and Visual Basic
Values true - Prefer events to be prefaced with this. in C# or Me. in Visual Basic.

false - Prefer events not to be prefaced with this. or Me..
Visual Studio default false:silent

Code examples:

// dotnet_style_qualification_for_event = true
this.Elapsed += Handler;

// dotnet_style_qualification_for_event = false
Elapsed += Handler;
' dotnet_style_qualification_for_event = true
AddHandler Me.Elapsed, AddressOf Handler

' dotnet_style_qualification_for_event = false
AddHandler Elapsed, AddressOf Handler

Language keywords instead of framework type names for type references

This style rule can be applied to local variables, method parameters, and class members, or as a separate rule to type member access expressions. A value of true means prefer the language keyword (for example, int or Integer) instead of the type name (for example, Int32) for types that have a keyword to represent them. A value of false means prefer the type name instead of the language keyword.

These rules could appear in an .editorconfig file as follows:

# CSharp and Visual Basic code style settings:
[*.{cs,vb}]
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
dotnet_style_predefined_type_for_member_access = true:suggestion

dotnet_style_predefined_type_for_locals_parameters_members

Rule name dotnet_style_predefined_type_for_locals_parameters_members
Rule ID IDE0012 and IDE0014
Applicable languages C# and Visual Basic
Values true - Prefer the language keyword for local variables, method parameters, and class members, instead of the type name, for types that have a keyword to represent them

false - Prefer the type name for local variables, method parameters, and class members, instead of the language keyword
Visual Studio default true:silent

Code examples:

// dotnet_style_predefined_type_for_locals_parameters_members = true
private int _member;

// dotnet_style_predefined_type_for_locals_parameters_members = false
private Int32 _member;
' dotnet_style_predefined_type_for_locals_parameters_members = true
Private _member As Integer

' dotnet_style_predefined_type_for_locals_parameters_members = false
Private _member As Int32

dotnet_style_predefined_type_for_member_access

Rule name dotnet_style_predefined_type_for_member_access
Rule ID IDE0013 and IDE0015
Applicable languages C# and Visual Basic
Values true - Prefer the language keyword for member access expressions, instead of the type name, for types that have a keyword to represent them

false - Prefer the type name for member access expressions, instead of the language keyword
Visual Studio default true:silent

Code examples:

// dotnet_style_predefined_type_for_member_access = true
var local = int.MaxValue;

// dotnet_style_predefined_type_for_member_access = false
var local = Int32.MaxValue;
' dotnet_style_predefined_type_for_member_access = true
Dim local = Integer.MaxValue

' dotnet_style_predefined_type_for_member_access = false
Dim local = Int32.MaxValue

Modifier preferences

The style rules in this section concern modifier preferences, including requiring accessibility modifiers, specifying the desired modifier sort order, and requiring the read-only modifier.

These rules could appear in an .editorconfig file as follows:

# CSharp and Visual Basic code style settings:
[*.{cs,vb}]
dotnet_style_require_accessibility_modifiers = always:suggestion
dotnet_style_readonly_field = true:warning

# CSharp code style settings:
[*.cs]
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion

# Visual Basic code style settings:
[*.vb]
visual_basic_preferred_modifier_order = Partial,Default,Private,Protected,Public,Friend,NotOverridable,Overridable,MustOverride,Overloads,Overrides,MustInherit,NotInheritable,Static,Shared,Shadows,ReadOnly,WriteOnly,Dim,Const,WithEvents,Widening,Narrowing,Custom,Async:suggestion

dotnet_style_require_accessibility_modifiers

Rule name dotnet_style_require_accessibility_modifiers
Rule ID IDE0040
Applicable languages C# and Visual Basic
Values always - Prefer accessibility modifiers to be specified.

for_non_interface_members - Prefer accessibility modifiers to be declared except for public interface members. (This is the same as always and has been added for future-proofing if C# adds default interface methods.)

never - Do not prefer accessibility modifiers to be specified.

omit_if_default - Prefer accessibility modifiers to be specified except if they are the default modifier.
Visual Studio default for_non_interface_members:silent
Introduced version Visual Studio 2017 version 15.5

Code examples:

// dotnet_style_require_accessibility_modifiers = always
// dotnet_style_require_accessibility_modifiers = for_non_interface_members
class MyClass
{
    private const string thisFieldIsConst = "constant";
}

// dotnet_style_require_accessibility_modifiers = never
class MyClass
{
    const string thisFieldIsConst = "constant";
}

csharp_preferred_modifier_order

Rule name csharp_preferred_modifier_order
Rule ID IDE0036
Applicable languages C#
Values One or more C# modifiers, such as public, private, and protected
Visual Studio default public, private, protected, internal, static, extern, new, virtual, abstract, sealed, override, readonly, unsafe, volatile, async:silent
Introduced version Visual Studio 2017 version 15.5
  • When this rule is set to a list of modifiers, prefer the specified ordering.
  • When this rule is omitted from the file, do not prefer a modifier order.

Code examples:

// csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async
class MyClass
{
    private static readonly int _daysInYear = 365;
}

visual_basic_preferred_modifier_order

Rule name visual_basic_preferred_modifier_order
Rule ID IDE0036
Applicable languages Visual Basic
Values One or more Visual Basic modifiers, such as Partial, Private, and Public
Visual Studio default Partial, Default, Private, Protected, Public, Friend, NotOverridable, Overridable, MustOverride, Overloads, Overrides, MustInherit, NotInheritable, Static, Shared, Shadows, ReadOnly, WriteOnly, Dim, Const,WithEvents, Widening, Narrowing, Custom, Async:silent
Introduced version Visual Studio 2017 version 15.5
  • When this rule is set to a list of modifiers, prefer the specified ordering.
  • When this rule is omitted from the file, do not prefer a modifier order.

Code examples:

' visual_basic_preferred_modifier_order = Partial,Default,Private,Protected,Public,Friend,NotOverridable,Overridable,MustOverride,Overloads,Overrides,MustInherit,NotInheritable,Static,Shared,Shadows,ReadOnly,WriteOnly,Dim,Const,WithEvents,Widening,Narrowing,Custom,Async
Public Class MyClass
    Private Shared ReadOnly daysInYear As Int = 365
End Class

visual_basic_style_unused_value_expression_statement_preference

Rule name visual_basic_style_unused_value_expression_statement_preference
Rule ID IDE0058
Applicable languages Visual Basic
Values unused_local_variable:silent
Visual Studio default unused_local_variable:silent

Code examples:

' visual_basic_style_unused_value_expression_statement_preference = unused_local_variable:silent

Dim unused = Computation()

visual_basic_style_unused_value_assignment_preference

Rule name visual_basic_style_unused_value_assignment_preference
Rule ID IDE0059
Applicable languages Visual Basic
Values unused_local_variable:silent
Visual Studio default unused_local_variable:silent

Code examples:

' visual_basic_style_unused_value_assignment_preference = unused_local_variable:suggestion

Dim unused = Computation()
Dim x = 1;

dotnet_style_readonly_field

Rule name dotnet_style_readonly_field
Rule ID IDE0044
Applicable languages C# and Visual Basic
Values true - Prefer that fields should be marked with readonly (C#) or ReadOnly (Visual Basic) if they are only ever assigned inline, or inside of a constructor

false - Specify no preference over whether fields should be marked with readonly (C#) or ReadOnly (Visual Basic)
Visual Studio default true:suggestion
Introduced version Visual Studio 2017 version 15.7

Code examples:

// dotnet_style_readonly_field = true
class MyClass
{
    private readonly int _daysInYear = 365;
}
' dotnet_style_readonly_field = true
Public Class MyClass
    Private ReadOnly daysInYear As Int = 365
End Class

Parentheses preferences

The style rules in this section concern parentheses preferences, including the use of parentheses for arithmetic, relational, and other binary operators.

These rules could appear in an .editorconfig file as follows:

# CSharp and Visual Basic code style settings:
[*.{cs,vb}]
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent

dotnet_style_parentheses_in_arithmetic_binary_operators

Rule name dotnet_style_parentheses_in_arithmetic_binary_operators
Rule ID IDE0047
Applicable languages C# and Visual Basic
Values always_for_clarity - Prefer parentheses to clarify arithmetic operator (*, /, %, +, -, <<, >>, &, ^, |) precedence

never_if_unnecessary - Prefer to not have parentheses when arithmetic operator (*, /, %, +, -, <<, >>, &, ^, |) precedence is obvious
Visual Studio default always_for_clarity:silent
Introduced version Visual Studio 2017 version 15.8

Code examples:

// dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity
var v = a + (b * c);

// dotnet_style_parentheses_in_arithmetic_binary_operators = never_if_unnecessary
var v = a + b * c;
' dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity
Dim v = a + (b * c)

' dotnet_style_parentheses_in_arithmetic_binary_operators = never_if_unnecessary
Dim v = a + b * c

dotnet_style_parentheses_in_relational_binary_operators

Rule name dotnet_style_parentheses_in_relational_binary_operators
Rule ID IDE0047
Applicable languages C# and Visual Basic
Values always_for_clarity - Prefer parentheses to clarify relational operator (>, <, <=, >=, is, as, ==, !=) precedence

never_if_unnecessary - Prefer to not have parentheses when relational operator (>, <, <=, >=, is, as, ==, !=) precedence is obvious
Visual Studio default always_for_clarity:silent
Introduced version Visual Studio 2017 version 15.8

Code examples:

// dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity
var v = (a < b) == (c > d);

// dotnet_style_parentheses_in_relational_binary_operators = never_if_unnecessary
var v = a < b == c > d;
' dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity
Dim v = (a < b) = (c > d)

' dotnet_style_parentheses_in_relational_binary_operators = never_if_unnecessary
Dim v = a < b = c > d

dotnet_style_parentheses_in_other_binary_operators

Rule name dotnet_style_parentheses_in_other_binary_operators
Rule ID IDE0047
Applicable languages C# and Visual Basic
Values always_for_clarity - Prefer parentheses to clarify other binary operator (&&, ||, ??) precedence

never_if_unnecessary - Prefer to not have parentheses when other binary operator (&&, ||, ??) precedence is obvious
Visual Studio default always_for_clarity:silent
Introduced version Visual Studio 2017 version 15.8

Code examples:

// dotnet_style_parentheses_in_other_binary_operators = always_for_clarity
var v = a || (b && c);

// dotnet_style_parentheses_in_other_binary_operators = never_if_unnecessary
var v = a || b && c;
' dotnet_style_parentheses_in_other_binary_operators = always_for_clarity
Dim v = a OrElse (b AndAlso c)

' dotnet_style_parentheses_in_other_binary_operators = never_if_unnecessary
Dim v = a OrElse b AndAlso c

dotnet_style_parentheses_in_other_operators

Rule name dotnet_style_parentheses_in_other_operators
Rule ID IDE0047
Applicable languages C# and Visual Basic
Values always_for_clarity - Prefer parentheses to clarify operator precedence

never_if_unnecessary - Prefer to not have parentheses when operator precedence is obvious
Visual Studio default never_if_unnecessary:silent
Introduced version Visual Studio 2017 version 15.8

Code examples:

// dotnet_style_parentheses_in_other_operators = always_for_clarity
var v = (a.b).Length;

// dotnet_style_parentheses_in_other_operators = never_if_unnecessary
var v = a.b.Length;
' dotnet_style_parentheses_in_other_operators = always_for_clarity
Dim v = (a.b).Length

' dotnet_style_parentheses_in_other_operators = never_if_unnecessary
Dim v = a.b.Length

Expression-level preferences

The style rules in this section concern expression-level preferences, including the use of object initializers, collection initializers, explicit or inferred tuple names, and inferred anonymous types.

These rules could appear in an .editorconfig file as follows:

# CSharp and Visual Basic code style settings:
[*.{cs,vb}]
dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_explicit_tuple_names = true:suggestion
dotnet_style_prefer_inferred_tuple_names = true:suggestion
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
dotnet_style_prefer_auto_properties = true:silent
dotnet_style_prefer_conditional_expression_over_assignment = true:suggestion
dotnet_style_prefer_conditional_expression_over_return = true:suggestion
dotnet_style_prefer_compound_assignment = true:suggestion

dotnet_style_object_initializer

Rule name dotnet_style_object_initializer
Rule ID IDE0017
Applicable languages C# and Visual Basic
Values true - Prefer objects to be initialized using object initializers when possible

false - Prefer objects to not be initialized using object initializers
Visual Studio default true:suggestion

Code examples:

// dotnet_style_object_initializer = true
var c = new Customer() { Age = 21 };

// dotnet_style_object_initializer = false
var c = new Customer();
c.Age = 21;
' dotnet_style_object_initializer = true
Dim c = New Customer() With {.Age = 21}

' dotnet_style_object_initializer = false
Dim c = New Customer()
c.Age = 21

dotnet_style_collection_initializer

Rule name dotnet_style_collection_initializer
Rule ID IDE0028
Applicable languages C# and Visual Basic
Values true - Prefer collections to be initialized using collection initializers when possible

false - Prefer collections to not be initialized using collection initializers
Visual Studio default true:suggestion

Code examples:

// dotnet_style_collection_initializer = true
var list = new List<int> { 1, 2, 3 };

// dotnet_style_collection_initializer = false
var list = new List<int>();
list.Add(1);
list.Add(2);
list.Add(3);
' dotnet_style_collection_initializer = true
Dim list = New List(Of Integer) From {1, 2, 3}

' dotnet_style_collection_initializer = false
Dim list = New List(Of Integer)
list.Add(1)
list.Add(2)
list.Add(3)

dotnet_style_explicit_tuple_names

Rule name dotnet_style_explicit_tuple_names
Rule ID IDE0033
Applicable languages C# 7.0+ and Visual Basic 15+
Values true - Prefer tuple names to ItemX properties

false - Prefer ItemX properties to tuple names
Visual Studio default true:suggestion

Code examples:

// dotnet_style_explicit_tuple_names = true
(string name, int age) customer = GetCustomer();
var name = customer.name;

// dotnet_style_explicit_tuple_names = false
(string name, int age) customer = GetCustomer();
var name = customer.Item1;
 ' dotnet_style_explicit_tuple_names = true
Dim customer As (name As String, age As Integer) = GetCustomer()
Dim name = customer.name

' dotnet_style_explicit_tuple_names = false
Dim customer As (name As String, age As Integer) = GetCustomer()
Dim name = customer.Item1

dotnet_style_prefer_inferred_tuple_names

Rule name dotnet_style_prefer_inferred_tuple_names
Rule ID IDE0037
Applicable languages C# 7.1+ and Visual Basic 15+
Values true - Prefer inferred tuple element names

false - Prefer explicit tuple element names
Visual Studio default true:suggestion
Introduced version Visual Studio 2017 version 15.6

Code examples:

// dotnet_style_prefer_inferred_tuple_names = true
var tuple = (age, name);

// dotnet_style_prefer_inferred_tuple_names = false
var tuple = (age: age, name: name);
' dotnet_style_prefer_inferred_tuple_names = true
Dim tuple = (name, age)

' dotnet_style_prefer_inferred_tuple_names = false
Dim tuple = (name:=name, age:=age)

dotnet_style_prefer_inferred_anonymous_type_member_names

Rule name dotnet_style_prefer_inferred_anonymous_type_member_names
Rule ID IDE0037
Applicable languages C# and Visual Basic
Values true - Prefer inferred anonymous type member names

false - Prefer explicit anonymous type member names
Visual Studio default true:suggestion
Introduced version Visual Studio 2017 version 15.6

Code examples:

// dotnet_style_prefer_inferred_anonymous_type_member_names = true
var anon = new { age, name };

// dotnet_style_prefer_inferred_anonymous_type_member_names = false
var anon = new { age = age, name = name };
' dotnet_style_prefer_inferred_anonymous_type_member_names = true
Dim anon = New With {name, age}

' dotnet_style_prefer_inferred_anonymous_type_member_names = false
Dim anon = New With {.name = name, .age = age}

dotnet_style_prefer_auto_properties

Rule name dotnet_style_prefer_auto_properties
Rule ID IDE0032
Applicable languages C# and Visual Basic
Values true - Prefer autoproperties over properties with private backing fields

false - Prefer properties with private backing fields over autoproperties
Visual Studio default true:suggestion
Introduced version Visual Studio 2017 version 15.7

Code examples:

// dotnet_style_prefer_auto_properties = true
private int Age { get; }

// dotnet_style_prefer_auto_properties = false
private int age;

public int Age
{
    get
    {
        return age;
    }
}
' dotnet_style_prefer_auto_properties = true
Public ReadOnly Property Age As Integer

' dotnet_style_prefer_auto_properties = false
Private _age As Integer

Public ReadOnly Property Age As Integer
    Get
        return _age
    End Get
End Property

dotnet_style_prefer_is_null_check_over_reference_equality_method

Rule name dotnet_style_prefer_is_null_check_over_reference_equality_method
Rule ID IDE0041
Applicable languages C# and Visual Basic
Values true - Prefer using a null check with pattern-matching over object.ReferenceEquals

false - Prefer object.ReferenceEquals over a null check with pattern-matching
Visual Studio default true:suggestion
Introduced version Visual Studio 2017 version 15.7

Code examples:

// dotnet_style_prefer_is_null_check_over_reference_equality_method = true
if (value is null)
    return;

// dotnet_style_prefer_is_null_check_over_reference_equality_method = false
if (object.ReferenceEquals(value, null))
    return;
' dotnet_style_prefer_is_null_check_over_reference_equality_method = true
If value Is Nothing
    Return
End If

' dotnet_style_prefer_is_null_check_over_reference_equality_method = false
If Object.ReferenceEquals(value, Nothing)
    Return
End If

dotnet_style_prefer_conditional_expression_over_assignment

Rule name dotnet_style_prefer_conditional_expression_over_assignment
Rule ID IDE0045
Applicable languages C# and Visual Basic
Values true - Prefer assignments with a ternary conditional over an if-else statement

false - Prefer assignments with an if-else statement over a ternary conditional
Visual Studio default true:suggestion
Introduced version Visual Studio 2017 version 15.8

Code examples:

// dotnet_style_prefer_conditional_expression_over_assignment = true
string s = expr ? "hello" : "world";

// dotnet_style_prefer_conditional_expression_over_assignment = false
string s;
if (expr)
{
    s = "hello";
}
else
{
    s = "world";
}
' dotnet_style_prefer_conditional_expression_over_assignment = true
Dim s As String = If(expr, "hello", "world")

' dotnet_style_prefer_conditional_expression_over_assignment = false
Dim s As String
If expr Then
    s = "hello"
Else
    s = "world"
End If

dotnet_style_prefer_conditional_expression_over_return

Rule name dotnet_style_prefer_conditional_expression_over_return
Rule ID IDE0046
Applicable languages C# and Visual Basic
Values true - Prefer return statements to use a ternary conditional over an if-else statement

false - Prefer return statements to use an if-else statement over a ternary conditional
Visual Studio default true:suggestion
Introduced version Visual Studio 2017 version 15.8

Code examples:

// dotnet_style_prefer_conditional_expression_over_return = true
return expr ? "hello" : "world"

// dotnet_style_prefer_conditional_expression_over_return = false
if (expr)
{
    return "hello";
}
else
{
    return "world";
}
' dotnet_style_prefer_conditional_expression_over_return = true
Return If(expr, "hello", "world")

' dotnet_style_prefer_conditional_expression_over_return = false
If expr Then
    Return "hello"
Else
    Return "world"
End If

dotnet_style_prefer_compound_assignment

Rule name dotnet_style_prefer_compound_assignment
Rule ID IDE0054
Applicable languages C# and Visual Basic
Values true - Prefer compound assignment expressions

false - Don't prefer compound assignment expressions
Visual Studio default true:suggestion

Code examples:

// dotnet_style_prefer_compound_assignment = true
x += 1;

// dotnet_style_prefer_compound_assignment = false
x = x + 1;
' dotnet_style_prefer_compound_assignment = true
x += 1

' dotnet_style_prefer_compound_assignment = false
x = x + 1

Null-checking preferences

The style rules in this section concern null-checking preferences.

These rules could appear in an .editorconfig file as follows:

# CSharp and Visual Basic code style settings:
[*.{cs,vb}]
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_null_propagation = true:suggestion
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:silent

dotnet_style_coalesce_expression

Rule name dotnet_style_coalesce_expression
Rule ID IDE0029
Applicable languages C# and Visual Basic
Values true - Prefer null coalescing expressions to ternary operator checking

false - Prefer ternary operator checking to null coalescing expressions
Visual Studio default true:suggestion

Code examples:

// dotnet_style_coalesce_expression = true
var v = x ?? y;

// dotnet_style_coalesce_expression = false
var v = x != null ? x : y; // or
var v = x == null ? y : x;
' dotnet_style_coalesce_expression = true
Dim v = If(x, y)

' dotnet_style_coalesce_expression = false
Dim v = If(x Is Nothing, y, x) ' or
Dim v = If(x IsNot Nothing, x, y)

dotnet_style_null_propagation

Rule name dotnet_style_null_propagation
Rule ID IDE0031
Applicable languages C# 6.0+ and Visual Basic 14+
Values true - Prefer to use null-conditional operator when possible

false - Prefer to use ternary null checking where possible
Visual Studio default true:suggestion

Code examples:

// dotnet_style_null_propagation = true
var v = o?.ToString();

// dotnet_style_null_propagation = false
var v = o == null ? null : o.ToString(); // or
var v = o != null ? o.String() : null;
' dotnet_style_null_propagation = true
Dim v = o?.ToString()

' dotnet_style_null_propagation = false
Dim v = If(o Is Nothing, Nothing, o.ToString()) ' or
Dim v = If(o IsNot Nothing, o.ToString(), Nothing)

dotnet_style_prefer_is_null_check_over_reference_equality_method

Rule name dotnet_style_prefer_is_null_check_over_reference_equality_method
Rule ID IDE0041
Applicable languages C# 6.0+ and Visual Basic 14+
Values true - Prefer is null check over reference equality method

false - Prefer reference equality method over is null check
Visual Studio default true:silent

.NET code quality settings

The quality rules in this section apply to both C# and Visual Basic code. They're used to configure code analyzers that are built into the Visual Studio integrated development environment (IDE). For information about configuring FxCop analyzers with an EditorConfig file, see Configure FxCop analyzers.

Parameter preferences

The quality rules in this section concern method parameters.

These rules could appear in an .editorconfig file as follows:

# CSharp and Visual Basic code quality settings:
[*.{cs,vb}]
dotnet_code_quality_unused_parameters = all:suggestion

dotnet_code_quality_unused_parameters

Rule name dotnet_code_quality_unused_parameters
Rule ID IDE0060
Applicable languages C# and Visual Basic
Values all - Flag methods with any accessibility that contain unused parameters

non_public - Flag only non-public methods that contain unused parameters
Visual Studio default all:suggestion

Code examples:

// dotnet_code_quality_unused_parameters = all:suggestion
public int GetNum() { return 1; }

// dotnet_code_quality_unused_parameters = non_public:suggestion
public int GetNum(int arg1) { return 1; }
' dotnet_code_quality_unused_parameters = all:suggestion
Public Function GetNum()
    Return 1
End Function

' dotnet_code_quality_unused_parameters = non_public:suggestion
Public Function GetNum(arg1 As Integer)
    Return 1
End Function

C# code style settings

The style rules in this section are applicable to C# only.

  • Implicit and explicit types
    • csharp_style_var_for_built_in_types
    • csharp_style_var_when_type_is_apparent
    • csharp_style_var_elsewhere
  • Expression-bodied members
    • csharp_style_expression_bodied_methods
    • csharp_style_expression_bodied_constructors
    • csharp_style_expression_bodied_operators
    • csharp_style_expression_bodied_properties
    • csharp_style_expression_bodied_indexers
    • csharp_style_expression_bodied_accessors
    • csharp_style_expression_bodied_lambdas
    • csharp_style_expression_bodied_local_functions
  • Pattern matching
    • csharp_style_pattern_matching_over_is_with_cast_check
    • csharp_style_pattern_matching_over_as_with_null_check
  • Inlined variable declarations
    • csharp_style_inlined_variable_declaration
  • Expression-level preferences
    • csharp_prefer_simple_default_expression
  • "Null" checking preferences
    • csharp_style_throw_expression
    • csharp_style_conditional_delegate_call
  • Modifier preferences
    • csharp_preferred_modifier_order
  • Code block preferences
    • csharp_prefer_braces
  • Unused value preferences
    • csharp_style_unused_value_expression_statement_preference
    • csharp_style_unused_value_assignment_preference
  • Index and range preferences
    • csharp_style_prefer_index_operator
    • csharp_style_prefer_range_operator
  • Miscellaneous preferences
    • csharp_style_deconstructed_variable_declaration
    • csharp_style_pattern_local_over_anonymous_function
    • csharp_using_directive_placement
    • csharp_prefer_static_local_function
    • csharp_prefer_simple_using_statement
    • csharp_style_prefer_switch_expression

Implicit and explicit types

The style rules in this section concern the use of the var keyword versus an explicit type in a variable declaration. This rule can be applied separately to built-in types, when the type is apparent, and elsewhere.

Example .editorconfig file:

# CSharp code style settings:
[*.cs]
csharp_style_var_for_built_in_types = true:suggestion
csharp_style_var_when_type_is_apparent = true:suggestion
csharp_style_var_elsewhere = true:suggestion

csharp_style_var_for_built_in_types

Rule name csharp_style_var_for_built_in_types
Rule ID IDE0007 and IDE0008
Applicable languages C#
Values true - Prefer var is used to declare variables with built-in system types such as int

false - Prefer explicit type over var to declare variables with built-in system types such as int
Visual Studio default true:silent

Code examples:

// csharp_style_var_for_built_in_types = true
var x = 5;

// csharp_style_var_for_built_in_types = false
int x = 5;

csharp_style_var_when_type_is_apparent

Rule name csharp_style_var_when_type_is_apparent
Rule ID IDE0007 and IDE0008
Applicable languages C#
Values true - Prefer var when the type is already mentioned on the right-hand side of a declaration expression

false - Prefer explicit type over var when the type is already mentioned on the right-hand side of a declaration expression
Visual Studio default true:silent

Code examples:

// csharp_style_var_when_type_is_apparent = true
var obj = new Customer();

// csharp_style_var_when_type_is_apparent = false
Customer obj = new Customer();

csharp_style_var_elsewhere

Rule name csharp_style_var_elsewhere
Rule ID IDE0007 and IDE0008
Applicable languages C#
Values true - Prefer var over explicit type in all cases, unless overridden by another code style rule

false - Prefer explicit type over var in all cases, unless overridden by another code style rule
Visual Studio default true:silent

Code examples:

// csharp_style_var_elsewhere = true
var f = this.Init();

// csharp_style_var_elsewhere = false
bool f = this.Init();

Expression-bodied members

The style rules in this section concern the use of expression-bodied members when the logic consists of a single expression. This rule can be applied to methods, constructors, operators, properties, indexers, and accessors.

Example .editorconfig file:

# CSharp code style settings:
[*.cs]
csharp_style_expression_bodied_methods = false:silent
csharp_style_expression_bodied_constructors = false:silent
csharp_style_expression_bodied_operators = false:silent
csharp_style_expression_bodied_properties = true:suggestion
csharp_style_expression_bodied_indexers = true:suggestion
csharp_style_expression_bodied_accessors = true:suggestion
csharp_style_expression_bodied_lambdas = true:silent
csharp_style_expression_bodied_local_functions = false:silent

csharp_style_expression_bodied_methods

Rule name csharp_style_expression_bodied_methods
Rule ID IDE0022
Applicable languages C# 6.0+
Values true - Prefer expression bodies for methods

when_on_single_line - Prefer expression bodies for methods when they will be a single line

false - Prefer block bodies for methods
Visual Studio default false:silent

Code examples:

// csharp_style_expression_bodied_methods = true
public int GetAge() => this.Age;

// csharp_style_expression_bodied_methods = false
public int GetAge() { return this.Age; }

csharp_style_expression_bodied_constructors

Rule name csharp_style_expression_bodied_constructors
Rule ID IDE0021
Applicable languages C# 7.0+
Values true - Prefer expression bodies for constructors

when_on_single_line - Prefer expression bodies for constructors when they will be a single line

false - Prefer block bodies for constructors
Visual Studio default false:silent

Code examples:

// csharp_style_expression_bodied_constructors = true
public Customer(int age) => Age = age;

// csharp_style_expression_bodied_constructors = false
public Customer(int age) { Age = age; }

csharp_style_expression_bodied_operators

Rule name csharp_style_expression_bodied_operators
Rule ID IDE0023 and IDE0024
Applicable languages C# 7.0+
Values true - Prefer expression bodies for operators

when_on_single_line - Prefer expression bodies for operators when they will be a single line

false - Prefer block bodies for operators
Visual Studio default false:silent

Code examples:

// csharp_style_expression_bodied_operators = true
public static ComplexNumber operator + (ComplexNumber c1, ComplexNumber c2)
    => new ComplexNumber(c1.Real + c2.Real, c1.Imaginary + c2.Imaginary);

// csharp_style_expression_bodied_operators = false
public static ComplexNumber operator + (ComplexNumber c1, ComplexNumber c2)
{ return new ComplexNumber(c1.Real + c2.Real, c1.Imaginary + c2.Imaginary); }

csharp_style_expression_bodied_properties

Rule name csharp_style_expression_bodied_properties
Rule ID IDE0025
Applicable languages C# 7.0+
Values true - Prefer expression bodies for properties

when_on_single_line - Prefer expression bodies for properties when they will be a single line

false - Prefer block bodies for properties
Visual Studio default true:silent

Code examples:

// csharp_style_expression_bodied_properties = true
public int Age => _age;

// csharp_style_expression_bodied_properties = false
public int Age { get { return _age; }}

csharp_style_expression_bodied_indexers

Rule name csharp_style_expression_bodied_indexers
Rule ID IDE0026
Applicable languages C# 7.0+
Values true - Prefer expression bodies for indexers

when_on_single_line - Prefer expression bodies for indexers when they will be a single line

false - Prefer block bodies for indexers
Visual Studio default true:silent

Code examples:

// csharp_style_expression_bodied_indexers = true
public T this[int i] => _values[i];

// csharp_style_expression_bodied_indexers = false
public T this[int i] { get { return _values[i]; } }

csharp_style_expression_bodied_accessors

Rule name csharp_style_expression_bodied_accessors
Rule ID IDE0027
Applicable languages C# 7.0+
Values true - Prefer expression bodies for accessors

when_on_single_line - Prefer expression bodies for accessors when they will be a single line

false - Prefer block bodies for accessors
Visual Studio default true:silent

Code examples:

// csharp_style_expression_bodied_accessors = true
public int Age { get => _age; set => _age = value; }

// csharp_style_expression_bodied_accessors = false
public int Age { get { return _age; } set { _age = value; } }

csharp_style_expression_bodied_lambdas

Rule name csharp_style_expression_bodied_lambdas
Rule ID IDE0053
Values true - Prefer expression bodies for lambdas

when_on_single_line - Prefer expression bodies for lambdas when they will be a single line

false - Prefer block bodies for lambdas
Visual Studio default true:silent

Code examples:

// csharp_style_expression_bodied_lambdas = true
Func<int, int> square = x => x * x;

// csharp_style_expression_bodied_lambdas = false
Func<int, int> square = x => { return x * x; };

csharp_style_expression_bodied_local_functions

Starting with C# 7.0, C# supports local functions. Local functions are private methods of a type that are nested in another member.

Rule name csharp_style_expression_bodied_local_functions
Rule ID IDE0061
Applicable languages C# 7.0+
Values true - Prefer expression bodies for local functions

when_on_single_line - Prefer expression bodies for local functions when they will be a single line

false - Prefer block bodies for local functions
Visual Studio default false:silent

Code examples:

// csharp_style_expression_bodied_local_functions = true
void M()
{
    Hello();
    void Hello() => Console.WriteLine("Hello");
}

// csharp_style_expression_bodied_local_functions = false
void M()
{
    Hello();
    void Hello()
    {
        Console.WriteLine("Hello");
    }
}

Pattern matching

The style rules in this section concern the use of pattern matching in C#.

Example .editorconfig file:

# CSharp code style settings:
[*.cs]
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion

csharp_style_pattern_matching_over_is_with_cast_check

Rule name csharp_style_pattern_matching_over_is_with_cast_check
Rule ID IDE0020
Applicable languages C# 7.0+
Values true - Prefer pattern matching instead of is expressions with type casts

false - Prefer is expressions with type casts instead of pattern matching
Visual Studio default true:suggestion

Code examples:

// csharp_style_pattern_matching_over_is_with_cast_check = true
if (o is int i) {...}

// csharp_style_pattern_matching_over_is_with_cast_check = false
if (o is int) {var i = (int)o; ... }

csharp_style_pattern_matching_over_as_with_null_check

Rule name csharp_style_pattern_matching_over_as_with_null_check
Rule ID IDE0019
Applicable languages C# 7.0+
Values true - Prefer pattern matching instead of as expressions with null checks to determine if something is of a particular type

false - Prefer as expressions with null checks instead of pattern matching to determine if something is of a particular type
Visual Studio default true:suggestion

Code examples:

// csharp_style_pattern_matching_over_as_with_null_check = true
if (o is string s) {...}

// csharp_style_pattern_matching_over_as_with_null_check = false
var s = o as string;
if (s != null) {...}

Inlined variable declarations

This style rule concerns whether out variables are declared inline or not. Starting in C# 7, you can declare an out variable in the argument list of a method call, rather than in a separate variable declaration.

csharp_style_inlined_variable_declaration

Rule name csharp_style_inlined_variable_declaration
Rule ID IDE0018
Applicable languages C# 7.0+
Values true - Prefer out variables to be declared inline in the argument list of a method call when possible

false - Prefer out variables to be declared before the method call
Visual Studio default true:suggestion

Code examples:

// csharp_style_inlined_variable_declaration = true
if (int.TryParse(value, out int i) {...}

// csharp_style_inlined_variable_declaration = false
int i;
if (int.TryParse(value, out i) {...}

Example .editorconfig file:

# CSharp code style settings:
[*.cs]
csharp_style_inlined_variable_declaration = true:suggestion

C# expression-level preferences

The style rules in this section concern expression-level preferences.

Example .editorconfig file:

# CSharp code style settings:
[*.cs]
csharp_prefer_simple_default_expression = true:suggestion

csharp_prefer_simple_default_expression

This style rule concerns using the default literal for default value expressions when the compiler can infer the type of the expression.

Rule name csharp_prefer_simple_default_expression
Rule ID IDE0034
Applicable languages C# 7.1+
Values true - Prefer default over default(T)

false - Prefer default(T) over default
Visual Studio default true:suggestion

Code examples:

// csharp_prefer_simple_default_expression = true
void DoWork(CancellationToken cancellationToken = default) { ... }

// csharp_prefer_simple_default_expression = false
void DoWork(CancellationToken cancellationToken = default(CancellationToken)) { ... }

C# null-checking preferences

These style rules concern the syntax around null checking, including using throw expressions or throw statements, and whether to perform a null check or use the conditional coalescing operator (?.) when invoking a lambda expression.

Example .editorconfig file:

# CSharp code style settings:
[*.cs]
csharp_style_throw_expression = true:suggestion
csharp_style_conditional_delegate_call = false:suggestion

csharp_style_throw_expression

Rule name csharp_style_throw_expression
Rule ID IDE0016
Applicable languages C# 7.0+
Values true - Prefer to use throw expressions instead of throw statements

false - Prefer to use throw statements instead of throw expressions
Visual Studio default true:suggestion

Code examples:

// csharp_style_throw_expression = true
this.s = s ?? throw new ArgumentNullException(nameof(s));

// csharp_style_throw_expression = false
if (s == null) { throw new ArgumentNullException(nameof(s)); }
this.s = s;

csharp_style_conditional_delegate_call

Rule name csharp_style_conditional_delegate_call
Rule ID IDE0041
Applicable languages C# 6.0+
Values true - refer to use the conditional coalescing operator (?.) when invoking a lambda expression, instead of performing a null check

false - Prefer to perform a null check before invoking a lambda expression, instead of using the conditional coalescing operator (?.)
Visual Studio default true:suggestion

Code examples:

// csharp_style_conditional_delegate_call = true
func?.Invoke(args);

// csharp_style_conditional_delegate_call = false
if (func != null) { func(args); }

Code block preferences

This style rule concerns the use of curly braces { } to surround code blocks.

Example .editorconfig file:

# CSharp code style settings:
[*.cs]
csharp_prefer_braces = true:silent

csharp_prefer_braces

Rule name csharp_prefer_braces
Rule ID IDE0011
Applicable languages C#
Values true - Prefer curly braces even for one line of code

false - Prefer no curly braces if allowed

when_multiline - Prefer curly braces on multiple lines
Visual Studio default true:silent

Code examples:

// csharp_prefer_braces = true
if (test) { this.Display(); }

// csharp_prefer_braces = false
if (test) this.Display();

Unused value preferences

These style rules concern unused expressions and value assignments.

Example .editorconfig file:

# CSharp code style settings:
[*.cs]
csharp_style_unused_value_expression_statement_preference = discard_variable:silent
csharp_style_unused_value_assignment_preference = discard_variable:suggestion

csharp_style_unused_value_expression_statement_preference

Rule name csharp_style_unused_value_expression_statement_preference
Rule ID IDE0058
Applicable languages C#
Values discard_variable - Prefer to assign an unused expression to a discard

unused_local_variable - Prefer to assign an unused expression to a local variable
Visual Studio default discard_variable:silent

Code examples:

// Original code:
System.Convert.ToInt32("35");

// After code fix for IDE0058:

// csharp_style_unused_value_expression_statement_preference = discard_variable
_ = System.Convert.ToInt32("35");

// csharp_style_unused_value_expression_statement_preference = unused_local_variable
var unused = Convert.ToInt32("35");

csharp_style_unused_value_assignment_preference

Rule name csharp_style_unused_value_assignment_preference
Rule ID IDE0059
Applicable languages C#
Values discard_variable - Prefer to use a discard when assigning a value that's not used

unused_local_variable - Prefer to use a local variable when assigning a value that's not used
Visual Studio default discard_variable:suggestion

Code examples:

// csharp_style_unused_value_assignment_preference = discard_variable
int GetCount(Dictionary<string, int> wordCount, string searchWord)
{
    _ = wordCount.TryGetValue(searchWord, out var count);
    return count;
}

// csharp_style_unused_value_assignment_preference = unused_local_variable
int GetCount(Dictionary<string, int> wordCount, string searchWord)
{
    var unused = wordCount.TryGetValue(searchWord, out var count);
    return count;
}

Index and range preferences

These style rules concern the use of index and range operators, which are available in C# 8.0 and later.

Example .editorconfig file:

# CSharp code style settings:
[*.cs]
csharp_style_prefer_index_operator = true:suggestion
csharp_style_prefer_range_operator = true:suggestion

csharp_style_prefer_index_operator

Rule name csharp_style_prefer_index_operator
Rule ID IDE0056
Applicable languages C# 8.0+
Values true - Prefer to use the ^ operator when calculating an index from the end of a collection

false - Don't prefer to use the ^ operator when calculating an index from the end of a collection
Visual Studio default true:suggestion

Code examples:

// csharp_style_prefer_index_operator = true
string[] names = { "Archimedes", "Pythagoras", "Euclid" };
var index = names[^1];

// csharp_style_prefer_index_operator = false
string[] names = { "Archimedes", "Pythagoras", "Euclid" };
var index = names[names.Length - 1];

csharp_style_prefer_range_operator

Rule name csharp_style_prefer_range_operator
Rule ID IDE0057
Applicable languages C# 8.0+
Values true - Prefer to use the range operator .. when extracting a "slice" of a collection

false - Don't prefer to use the range operator .. when extracting a "slice" of a collection
Visual Studio default true:suggestion

Code examples:

// csharp_style_prefer_range_operator = true
string sentence = "the quick brown fox";
var sub = sentence[0..^4];

// csharp_style_prefer_range_operator = false
string sentence = "the quick brown fox";
var sub = sentence.Substring(0, sentence.Length - 4);

Miscellaneous preferences

This section contains miscellaneous style rules.

Example .editorconfig file:

# CSharp code style settings:
[*.cs]
csharp_style_deconstructed_variable_declaration = true:suggestion
csharp_style_pattern_local_over_anonymous_function = true:suggestion
csharp_using_directive_placement = outside_namespace:silent
csharp_prefer_static_local_function = true:suggestion
csharp_prefer_simple_using_statement = true:suggestion
csharp_style_prefer_switch_expression = true:suggestion

csharp_style_deconstructed_variable_declaration

Rule name csharp_style_deconstructed_variable_declaration
Rule ID IDE0042
Applicable languages C# 7.0+
Values true - Prefer deconstructed variable declaration

false - Do not prefer deconstruction in variable declarations
Visual Studio default true:suggestion

Code examples:

// csharp_style_deconstructed_variable_declaration = true
var (name, age) = GetPersonTuple();
Console.WriteLine($"{name} {age}");

(int x, int y) = GetPointTuple();
Console.WriteLine($"{x} {y}");

// csharp_style_deconstructed_variable_declaration = false
var person = GetPersonTuple();
Console.WriteLine($"{person.name} {person.age}");

(int x, int y) point = GetPointTuple();
Console.WriteLine($"{point.x} {point.y}");

csharp_style_pattern_local_over_anonymous_function

Starting with C# 7.0, C# supports local functions. Local functions are private methods of a type that are nested in another member.

Rule name csharp_style_pattern_local_over_anonymous_function
Rule ID IDE0039
Applicable languages C# 7.0+
Values true - Prefer local functions over anonymous functions

false - Prefer anonymous functions over local functions
Visual Studio default true:suggestion

Code examples:

// csharp_style_pattern_local_over_anonymous_function = true
int fibonacci(int n)
{
    return n <= 1 ? 1 : fibonacci(n-1) + fibonacci(n-2);
}

// csharp_style_pattern_local_over_anonymous_function = false
Func<int, int> fibonacci = null;
fibonacci = (int n) =>
{
    return n <= 1 ? 1 : fibonacci(n - 1) + fibonacci(n - 2);
};

csharp_using_directive_placement

Rule name csharp_using_directive_placement
Rule ID IDE0065
Applicable languages C#
Values outside_namespace - Prefer using directives to be placed outside the namespace

inside_namespace - Prefer using directives to be placed inside the namespace
Visual Studio default outside_namespace:silent

Code examples:

// csharp_using_directive_placement = outside_namespace
using System;

namespace Conventions
{
    ...
}

// csharp_using_directive_placement = inside_namespace
namespace Conventions
{
    using System;
    ...
}

csharp_prefer_static_local_function

Rule name csharp_prefer_static_local_function
Rule ID IDE0062
Applicable languages C# 8.0+
Values true - Prefer local functions to be marked static

false - Don't prefer local functions to be marked static
Visual Studio default true:suggestion

Code examples:

// csharp_prefer_static_local_function = true
void M()
{
    Hello();
    static void Hello()
    {
        Console.WriteLine("Hello");
    }
}

// csharp_prefer_static_local_function = false
void M()
{
    Hello();
    void Hello()
    {
        Console.WriteLine("Hello");
    }
}

csharp_prefer_simple_using_statement

Rule name csharp_prefer_simple_using_statement
Rule ID IDE0063
Applicable languages C# 8.0+
Values true - Prefer to use a simple using statement

false - Don't prefer to use a simple using statement
Visual Studio default true:suggestion

Code examples:

// csharp_prefer_simple_using_statement = true
using var a = b;

// csharp_prefer_simple_using_statement = false
using (var a = b) { }

csharp_style_prefer_switch_expression

Rule name csharp_style_prefer_switch_expression
Rule ID IDE0066
Applicable languages C# 8.0+
Values true - Prefer to use a switch expression (introduced with C# 8.0)

false - Prefer to use a switch statement
Visual Studio default true:suggestion
Introduced version Visual Studio 2019 version 16.2

Code examples:

// csharp_style_prefer_switch_expression = true
return x switch
{
    1 => 1 * 1,
    2 => 2 * 2,
    _ => 0,
};

// csharp_style_prefer_switch_expression = false
switch (x)
{
    case 1:
        return 1 * 1;
    case 2:
        return 2 * 2;
    default:
        return 0;
}

See also