Skip to content

Naming: Fields, Parameters and Locals

Rule prefix: NAM · Baseline: C# 14 / .NET 10 · Levels: DO · DO NOT · CONSIDER · AVOID

Home · Rule index · Naming cheat sheet

This chapter names the identifiers inside a type and inside a method body: fields, constants, parameters, locals, and the small kinds that live in a body (tuple elements, pattern variables, LINQ range variables, catch variables, anonymous-type members and labels).

Private and internal instance fields and mutable static fields, including [ThreadStatic] fields, are named with _ followed by camelCase (_lines, _ordersPlaced, _depth). Private and internal static readonly fields use PascalCase with no prefix (SharedClient, OrderNumberFormat). The s_ and t_ prefixes are not used: private and internal static fields follow the ReSharper defaults for private static fields. Everything else has no prefix. Parameters and locals use camelCase, and a local constant may use camelCase or PascalCase (camelCase preferred); constant fields, public fields and tuple elements in signatures use PascalCase, and a protected instance field uses PascalCase or _ followed by camelCase. The Framework Design Guidelines forbid prefixes only on names visible outside the assembly.

Names of types, methods, properties and events are on page 03. Declaration rules for fields and locals (const versus static readonly, readonly, initialisation) are on page 06.

IDE1006 enforces most rules in this chapter through the naming rules in config/.editorconfig. It checks the prefix, the first letter and, through the word_separator = _ setting on the camelCase styles, a lower-case word after an inner underscore. A capitalised word after an inner underscore (_max_Count, _order_Total) passes IDE1006, and so does an inner underscore in a static readonly field (Shared_Client), because pascal_case has no word separator; reviewers check both. Four rules have no tool check and are checked in review: NAM-234, NAM-237, NAM-240 and NAM-241 (TOOL-018). NAM-216 is a CONSIDER rule that ships at none: the build reports nothing, and the only check is ReSharper InconsistentNaming in the editor, which expects camelCase. The build enforces NAM-203 on public fields only.

Rule index

ID Level Rule Enforced
NAM-200 DO name a private, internal or private protected instance field with _ followed by a camelCase noun (_lines, _timeProvider). IDE1006, ReSharper: InconsistentNaming
NAM-201 DO name a private readonly instance field with _ followed by camelCase, exactly like other private instance fields; readonly never changes the name. IDE1006, ReSharper: InconsistentNaming
NAM-202 DO name an internal instance field with _ followed by camelCase, the same as a private field. IDE1006
NAM-203 DO name a public instance field in PascalCase and declare it only in a struct that mirrors a native or wire layout; name a protected or protected internal instance field in PascalCase or with _ followed by camelCase. IDE1006 (public fields only)
NAM-204 DO name an explicit backing field after its property in camelCase with the _ prefix (_displayName for DisplayName), and declare one only when the C# 14 field keyword cannot do the job. IDE1006, ReSharper: InconsistentNaming
NAM-205 DO NOT encode the type, scope or kind in a name with prefixes such as m_, str, i, b, obj or p; name the meaning instead. IDE1006
NAM-206 DO NOT write a constant or field name in SCREAMING_CASE (MAX_ORDER_LINES), including in code ported from other languages; use PascalCase for constant fields (NAM-214) and camelCase or PascalCase for local constants (NAM-216). CA1707
NAM-210 DO name a private, internal or private protected static field that is not readonly, including a [ThreadStatic] field, with _ followed by camelCase, exactly like an instance field (_ordersPlaced, _retryCount), and never with an s_ prefix. IDE1006, ReSharper: InconsistentNaming
NAM-211 DO name a private, internal or private protected static readonly field in PascalCase with no prefix (SharedClient, OrderNumberFormat), never with s_ or _. IDE1006, ReSharper: InconsistentNaming
NAM-212 DO name a [ThreadStatic] field like any other private static field, _ followed by camelCase (_depth), never with a t_ prefix, and consider ThreadLocal<T> or AsyncLocal<T> instead (VAR-514). IDE1006, ReSharper: InconsistentNaming
NAM-213 DO name a public, protected or protected internal static readonly field in PascalCase with no prefix (DefaultTimeout, Empty). IDE1006
NAM-214 DO name a constant field of any accessibility in PascalCase with no prefix (MaxLinesPerOrder, HttpsPort). IDE1006
NAM-215 DO name a private constant in PascalCase with no prefix (MaxRetries). IDE1006
NAM-216 CONSIDER name a local constant in camelCase (const int maxAttempts = 3;); PascalCase (MaxAttempts) is accepted. ReSharper: InconsistentNaming (IDE only)
NAM-220 DO name a parameter in camelCase after its meaning rather than its type (orderTotal, customerId, cancellationToken). IDE1006, ReSharper: InconsistentNaming
NAM-221 DO name primary-constructor parameters of classes and structs in camelCase and the parameters of positional records in PascalCase, because record parameters become public properties. IDE1006
NAM-222 DO name a constructor parameter that initializes a field after that field without its _ prefix (trackingNumber initializes _trackingNumber). IDE1006
NAM-223 DO name the this parameter of an extension method in camelCase after the extended type or its role (this Invoice invoice), never self, obj or @this. IDE1006
NAM-224 DO name out, ref, in, ref readonly and scoped parameters in camelCase after their meaning, without a direction prefix such as out, ref or result. IDE1006
NAM-225 DO name a params parameter with a plural camelCase noun (skus, lines). IDE1006
NAM-226 DO name an optional parameter in camelCase like any other parameter, after its meaning, not after its default value. IDE1006
NAM-227 DO write a named argument with exactly the parameter name in camelCase (totalWidth: 3), and use named arguments for bool, null and numeric literals whose meaning the call does not show. CS1739
NAM-230 DO name a local variable in camelCase with a noun that says what it holds (orderTotal, shippedOrders), using single letters only for loop counters (NAM-231); a local constant follows NAM-216. IDE1006
NAM-231 DO name a for counter i, then j and k for nested loops, and a foreach variable with the singular noun of the element (foreach (OrderLine line in order.Lines)). IDE1006
NAM-232 DO name a lambda parameter in camelCase after the element it represents (order => order.Total), using a single letter only in a lambda that fits on one line and has one parameter. IDE1006
NAM-233 DO use the discard _ for a value you deliberately ignore (out _, _ = dictionary.Remove(key), (_, decimal total)), and never declare a named variable that is assigned but never read. IDE0059
NAM-234 DO name tuple elements in method signatures, properties and fields in PascalCase ((int Count, decimal Total)), and the variables you deconstruct them into in camelCase (NAM-235). Manual
NAM-235 DO name variables introduced by deconstruction in camelCase ((int count, decimal total) = Summarize(lines);). IDE1006
NAM-236 DO name pattern variables in camelCase after what they hold (payment is CardPayment card). IDE1006
NAM-237 DO name LINQ range variables and LINQ lambda parameters with the singular camelCase noun of the element (from order in orders, orders.Where(order => order.IsShipped)). Manual
NAM-238 DO name a variable declared by a using declaration or statement in camelCase after the resource (using var buffer = new MemoryStream();). IDE1006
NAM-239 DO name the exception variable of a catch clause ex, and omit the variable when the handler does not use it (catch (FormatException)). IDE1006
NAM-240 DO name anonymous-type members in PascalCase, either explicitly (new { OrderId = order.Id }) or by projecting a PascalCase property (new { order.Total }). Manual
NAM-241 DO name a statement label in PascalCase (RetryPayment:) and add a label only where a goto is clearer than a loop or a method (see LANG-061). Manual

Instance fields

These rules name instance fields of every accessibility and explicit backing fields, and they ban type prefixes and SCREAMING_CASE names.

NAM-200

DO name a private, internal or private protected instance field with _ followed by a camelCase noun (_lines, _timeProvider).

✅ Correct

private readonly List<OrderLine> _lines = [];

public int LineCount => _lines.Count;

❌ Incorrect — private field without the _ prefix

private readonly List<OrderLine> lines = []; // Missing prefix: '_'

public int LineCount => lines.Count;

Why: With the prefix, _lines cannot be mistaken for a parameter or local named lines at any read site, and no this. is needed to tell them apart (TYPE-014). Microsoft's identifier rules and the runtime style use _camelCase for these fields. The Framework Design Guidelines ban prefixes only on names visible outside the assembly, so they do not apply to private state. Mutable static fields follow the same _ prefix (NAM-210), and internal fields follow these private rules. Aviva and StyleCop (SA1309) use plain camelCase for private fields. m_ prefixes (NAM-205) and snake_case after the prefix are not used.

See also: VAR-512 (instance fields stay private).

Scope: Private, internal and private protected instance fields (readonly or not) · Enforced: IDE1006, ReSharper: InconsistentNaming. IDE1006 checks the prefix, the first letter and, through the word separator, a lower-case word after an inner underscore; a capitalised word after an inner underscore (_max_Count, _order_Total) passes IDE1006, so reviewers check it. ReSharper agrees for private instance fields (its default for "Instance fields (private)" in the JetBrains naming options is _aaBb); its default covers private fields only · Config: dotnet_naming_rule.nam_200_private_fields.*, resharper_csharp_naming_rule.private_instance_fields · Sources: MS-IDNAME, RT-STYLE, RT-EC, ROSLYN, RD-NAMING, RS-NAMING-OPT

NAM-201

DO name a private readonly instance field with _ followed by camelCase, exactly like other private instance fields; readonly never changes the name.

✅ Correct

namespace Contoso.Orders;

public sealed class OrderStamp
{
    private readonly TimeProvider _timeProvider;

    public OrderStamp(TimeProvider timeProvider)
    {
        ArgumentNullException.ThrowIfNull(timeProvider);
        _timeProvider = timeProvider;
    }

    public DateTimeOffset Now => _timeProvider.GetUtcNow();
}

❌ Incorrect — readonly field in PascalCase

namespace Contoso.Orders;

public sealed class OrderStamp
{
    private readonly TimeProvider TimeProvider; // Missing prefix: '_'

    public OrderStamp(TimeProvider timeProvider)
    {
        ArgumentNullException.ThrowIfNull(timeProvider);
        TimeProvider = timeProvider;
    }

    public DateTimeOffset Now => TimeProvider.GetUtcNow();
}

Why: The prefix states scope and readonly states mutability; the declaration already shows readonly. A second naming style for readonly fields would give one type two styles for the same kind of member, and renaming a field whenever readonly is added or removed would touch every reader. A field named TimeProvider also shares its name with its type, so TimeProvider.GetUtcNow() is easy to read as a static call. The time source is injected through the constructor, not read from TimeProvider.System, so tests can replace it.

See also: VAR-510 (const and static readonly choice).

Scope: Private readonly instance fields · Enforced: IDE1006 (what it checks: see NAM-200), ReSharper: InconsistentNaming · Config: dotnet_naming_rule.nam_200_private_fields.*, resharper_csharp_naming_rule.private_instance_fields · Sources: MS-IDNAME, RT-STYLE, ROSLYN

NAM-202

DO name an internal instance field with _ followed by camelCase, the same as a private field.

✅ Correct

internal int _retryCount;

internal void RecordRetry() => _retryCount++;

❌ Incorrect — internal field in PascalCase

internal int RetryCount; // Missing prefix: '_'

internal void RecordRetry() => RetryCount++;

Why: An internal field is visible to the whole assembly but not to callers outside it, so it sits on the non-public side of the Framework Design Guidelines boundary (NAM-200). VAR-512 allows non-private instance fields only in interop-layout structs and generated code, so prefer a private field. Aviva uses PascalCase for public fields. ReSharper's _aaBb default is defined for "Instance fields (private)".

See also: VAR-512 (instance fields stay private).

Scope: Internal instance fields, which VAR-512 allows only in interop-layout structs and generated code · Enforced: IDE1006 (what it checks: see NAM-200) · Config: dotnet_naming_rule.nam_200_private_fields.*, resharper_csharp_naming_rule.private_instance_fields · Sources: MS-IDNAME, RT-EC, GOOG, RS-NAMING-OPT

NAM-203

DO name a public instance field in PascalCase and declare it only in a struct that mirrors a native or wire layout; name a protected or protected internal instance field in PascalCase or with _ followed by camelCase.

✅ Correct

namespace Contoso.Orders;

[System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)]
public struct NativePoint
{
    public int X;
    public int Y;
}

❌ Incorrect — public field in camelCase

namespace Contoso.Orders;

[System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)]
public struct NativePoint
{
    public int x; // Public field must begin with an upper case character
    public int Y;
}

✅ Accepted — protected instance fields in either style

namespace Contoso.Orders;

internal abstract class ShipmentStep
{
    protected int _attempts = 1; // _camelCase

    protected int RetryLimit = 3; // PascalCase

    public bool CanRetry() => _attempts < RetryLimit;
}

Why: A field is part of a type's memory layout and a property is not, so a struct that must match a native or wire layout declares fields. Every other public or protected member exposes data through a property (VAR-512). A public field is part of the API that callers type, so it follows the Framework Design Guidelines: PascalCase, no prefix; the guidelines forbid prefixes on public fields. A protected field is seen by subclasses, not by every caller, and this guide accepts both styles there. That is a house convention: the guidelines also forbid prefixes on every name visible outside the assembly, protected ones included. The ReSharper naming option for non-private fields lists both styles, so ReSharper accepts either on every non-private field, while the build enforces PascalCase on public fields only. This is a known trade-off: ReSharper's public-field setting accepts both PascalCase and _camelCase, so it does not flag _count on a public field, but the build rejects it. No shipped naming rule checks protected and protected internal instance fields at all, so reviewers check them.

The build still reports a visible protected field in a public type: CA1051 reports the field itself, whatever its name. So _camelCase fits a protected field in a type that is not externally visible, and a protected field of a public type is better replaced by a property. A protected static mutable field is not named by this rule: CA2211 reports it (VAR-513).

See also: VAR-512 (why only interop structs may expose fields), NAM-213 (public static readonly fields).

Scope: Public instance fields (allowed only in interop structs, VAR-512), and protected and protected internal instance fields (either style) · Enforced: IDE1006 for public fields only; ReSharper: InconsistentNaming accepts PascalCase and _ followed by camelCase on every non-private field; CA1051 reports visible instance fields of public types; no shipped naming rule checks protected and protected internal instance fields (reviewed only) · Config: dotnet_naming_rule.nam_203_public_fields.*, resharper_csharp_naming_rule.public_fields · Sources: MS-FDG-FIELD, MS-IDNAME, MS-FDG-MEMBERS

NAM-204

DO name an explicit backing field after its property in camelCase with the _ prefix (_displayName for DisplayName), and declare one only when the C# 14 field keyword cannot do the job.

✅ Correct

private readonly List<string> _tags = [];

public IReadOnlyList<string> Tags => _tags;

public void AddTag(string tag) => _tags.Add(tag);

❌ Incorrect — backing field without the _ prefix

private readonly List<string> tags = []; // Missing prefix: '_'

public IReadOnlyList<string> Tags => tags;

public void AddTag(string tag) => tags.Add(tag);

Why: The field keyword gives an accessor the compiler-generated backing field, so most properties need no declared field at all (VAR-523). A declared field is justified only when field cannot do the job: above, the field type (List<string>) differs from the property type (IReadOnlyList<string>) and AddTag mutates the list. Naming the field _ plus the camelCase property name (_tags for Tags, _displayName for DisplayName) makes the pair visible in the file.

See also: VAR-523 (use field instead of an explicit backing field).

Scope: Explicit backing fields of properties (prefer the field keyword, VAR-523) · Enforced: IDE1006 (what it checks: see NAM-200), ReSharper: InconsistentNaming · Config: dotnet_naming_rule.nam_200_private_fields.*, resharper_csharp_naming_rule.private_instance_fields · Sources: MS-IDNAME, MS-LANG-14

NAM-205

DO NOT encode the type, scope or kind in a name with prefixes such as m_, str, i, b, obj or p; name the meaning instead.

✅ Correct

private readonly string _customerName = "";

public int NameLength => _customerName.Length;

❌ Incorrect — m_ prefix on a field, type prefixes on a parameter and a local

private readonly string m_customerName = ""; // m_ prefix; Missing prefix: '_'

public int NameLength => m_customerName.Length;

public static int CountLetters(string strName) // 'str' type prefix on a parameter
{
    int iCount = strName.Count(char.IsLetter); // 'i' type prefix on a local

    return iCount;
}

Why: The compiler and the editor already show the type of every name, so strName and iCount repeat information that goes stale when the type changes. The name should say what the value means. Hungarian notation is the practice this rule bans. IDE1006 catches m_ on a field because it demands the _ prefix; it cannot see strName or iCount in a local or parameter, so reviewers check those.

Exceptions: The scope prefix _ defined by NAM-200, NAM-210 and NAM-212 is the only allowed one. The loop counters i, j and k (NAM-231) are counter names, not type prefixes.

See also: VAR-512 (field declaration rules).

Scope: Every field, parameter and local name · Enforced: IDE1006 · Config: dotnet_naming_rule.nam_200_private_fields.*, resharper_csharp_naming_rule.private_instance_fields · Sources: MS-FDG-GENERAL, MS-CONV, SA, AV

NAM-206

DO NOT write a constant or field name in SCREAMING_CASE (MAX_ORDER_LINES), including in code ported from other languages; use PascalCase for constant fields (NAM-214) and camelCase or PascalCase for local constants (NAM-216).

✅ Correct

namespace Contoso.Orders;

public static class HttpPorts
{
    public const int HttpsPort = 443;
}

❌ Incorrect — SCREAMING_CASE constant

namespace Contoso.Orders;

public static class HttpPorts
{
    public const int HTTPS_PORT = 443; // SCREAMING_CASE name; remove the underscores
}

Why: .NET names constant fields in PascalCase at every accessibility (NAM-214), local constants take camelCase or PascalCase (NAM-216), and underscores are allowed only in the leading _ of an instance or mutable static field, the discard and test method names (NAM-016). SCREAMING_CASE is the convention of other languages; ported names are renamed when they move. CA1707 reports the underscores on externally visible (public and protected) constants and static readonly fields only. IDE1006 does not report MAX_ORDER_LINES, because the PascalCase check looks only at the first letter, so a private or local constant written this way passes every shipped tool and is caught in review. With StyleCop opted in, SA1310 also reports private SCREAMING_CASE constants (TOOL-016).

Exceptions: A constant that must match a native header or wire contract (for example a P/Invoke value) may keep the native name. Suppress CA1707 on that member with [SuppressMessage("Naming", "CA1707", Justification = "...")] and state the header in the justification.

See also: VAR-510 (const versus static readonly).

Scope: Constants and fields of every accessibility (CA1707 checks externally visible, that is public and protected, constants and static readonly fields; other SCREAMING_CASE names are reviewed) · Enforced: CA1707 reports externally visible (public and protected) constants and static readonly fields only; private and local constants such as MAX_ITEMS pass every shipped tool and are reviewed · Sources: MS-IDNAME, MS-FDG-CAPS, MS-CA, RT-STYLE

Static fields and constants

These rules name mutable static, static readonly and thread-static fields, and constants of every accessibility, including local constants.

NAM-210

DO name a private, internal or private protected static field that is not readonly, including a [ThreadStatic] field, with _ followed by camelCase, exactly like an instance field (_ordersPlaced, _retryCount), and never with an s_ prefix.

✅ Correct

private static int _ordersPlaced;

public static int GetNextOrderNumber() => Interlocked.Increment(ref _ordersPlaced);

❌ Incorrect — static field with the s_ prefix

private static int s_ordersPlaced; // s_ prefix; Missing prefix: '_'

public static int GetNextOrderNumber() => Interlocked.Increment(ref s_ordersPlaced);

Why: ReSharper's default for private static fields is _aaBb, and internal static fields follow it. A mutable static field is named like an instance field: _ followed by camelCase. The static keyword, not the name, tells a reader that the field is shared by every instance and every thread. Only the single _ prefix is allowed, because the Framework Design Guidelines ban prefixes only on names visible outside the assembly, and camelCase follows it with no further underscore. Microsoft's identifier rules and dotnet/runtime use an s_ prefix followed by camelCase for private and internal static fields, and Aviva uses PascalCase for mutable static fields.

Exceptions: Static readonly fields use PascalCase with no prefix (NAM-211). Thread-static fields follow this rule (NAM-212). Constants use PascalCase (NAM-214).

See also: VAR-513 (static fields stay private or readonly).

Scope: Private, internal and private protected mutable static fields (static readonly: NAM-211; thread-static: NAM-212; constants: NAM-214) · Enforced: IDE1006, ReSharper: InconsistentNaming. IDE1006 checks the prefix, the first letter and, through the word separator, a lower-case word after an inner underscore; a capitalised word after an inner underscore (_max_Count, _order_Total) passes IDE1006, so reviewers check it. ReSharper agrees for private static fields (its default for "Static fields (private)" in the JetBrains naming options is _aaBb); its default covers private fields only · Config: dotnet_naming_rule.nam_210_static_fields.*, resharper_csharp_naming_rule.private_static_fields · Sources: RD-NAMING, RS-NAMING, RS-NAMING-OPT, MS-IDNAME, RT-STYLE, GOOG

NAM-211

DO name a private, internal or private protected static readonly field in PascalCase with no prefix (SharedClient, OrderNumberFormat), never with s_ or _.

✅ Correct

private static readonly System.Text.CompositeFormat OrderNumberFormat =
    System.Text.CompositeFormat.Parse("ORD-{0:D6}");

public static string FormatOrderNumber(int orderId) =>
    string.Format(System.Globalization.CultureInfo.InvariantCulture, OrderNumberFormat, orderId);

❌ Incorrect — private static readonly field with the s_ prefix

private static readonly HttpClient s_sharedClient = new(); // s_ prefix; Prefix 's_' is not expected

public static void CancelAll() => s_sharedClient.CancelPendingRequests();

Why: Static readonly fields of every accessibility share PascalCase (NAM-213), as in the ReSharper default. A reader tells them from mutable static fields by the name (_ordersPlaced against OrderNumberFormat) and from properties by the declaration (a static readonly field against { get; }). At the call site a PascalCase static readonly field reads like a get-only property on purpose, because both are read-only values to the caller. A _gate name is also reported (private static readonly object _gate = new(); gives "Prefix '_' is not expected"). ReSharper agrees (its default "Static readonly fields (private)" is AaBb in the JetBrains naming options), and with StyleCop opted in SA1311 agrees as well. An inner underscore such as Shared_Client passes IDE1006, because pascal_case has no word separator; reviewers check it, and SA1310 reports it when StyleCop is opted in. Microsoft's identifier rules and dotnet/runtime use an s_ prefix followed by camelCase for static readonly fields, and Google style uses _camelCase.

See also: VAR-510 (const versus static readonly).

Scope: Private, internal and private protected static readonly fields (public ones: NAM-213, the same style) · Enforced: IDE1006 (prefix and first letter), ReSharper: InconsistentNaming · Config: dotnet_naming_rule.nam_211_static_readonly_fields.*, resharper_csharp_naming_rule.private_static_readonly · Sources: RD-NAMING, RS-NAMING, RS-NAMING-OPT, MS-IDNAME, AV, SA

NAM-212

DO name a [ThreadStatic] field like any other private static field, _ followed by camelCase (_depth), never with a t_ prefix, and consider ThreadLocal<T> or AsyncLocal<T> instead (VAR-514).

✅ Correct

[ThreadStatic]
private static int _depth;

public static int EnterScope()
{
    _depth++;

    return _depth;
}

❌ Incorrect — thread-static field with the t_ prefix

[ThreadStatic]
private static int t_depth; // t_ prefix; Missing prefix: '_'

public static int EnterScope()
{
    t_depth++;

    return t_depth;
}

Why: No naming tool can select the [ThreadStatic] attribute, so the field follows the static-field rule (NAM-210); ReSharper has no thread-static rule either. The attribute, not the name, shows that each thread sees its own value. IDE1006 reports t_depth with "Missing prefix: '_'" on the field line, so the field needs no suppression. Prefer ThreadLocal<T> or AsyncLocal<T> over [ThreadStatic] (VAR-514). Microsoft's identifier rules and dotnet/runtime use a t_ prefix followed by camelCase for thread-static fields, which IDE1006 reports unless each field is suppressed.

Exceptions: Do not initialize a thread-static field inline; only the first thread would see the initial value (VAR-514).

See also: VAR-514 (per-thread and per-flow state).

Scope: Fields marked [ThreadStatic] · Enforced: IDE1006, ReSharper: InconsistentNaming (through the NAM-210 naming rule; no tool can select the attribute, so the field is checked like any other static field) · Config: dotnet_naming_rule.nam_210_static_fields.*, resharper_csharp_naming_rule.private_static_fields · Sources: RD-NAMING, RS-NAMING-OPT, MS-IDNAME, RT-STYLE

NAM-213

DO name a public, protected or protected internal static readonly field in PascalCase with no prefix (DefaultTimeout, Empty).

✅ Correct

namespace Contoso.Orders;

public static class OrderDefaults
{
    public static readonly TimeSpan DefaultTimeout = TimeSpan.FromSeconds(30);
}

❌ Incorrect — prefix on a public static readonly field

namespace Contoso.Orders;

public static class OrderDefaults
{
    public static readonly TimeSpan s_defaultTimeout = // Public field must begin with an upper case character
        TimeSpan.FromSeconds(30);
}

Why: A public static readonly field is part of the API that callers type in their own code (string.Empty, OrderDefaults.DefaultTimeout). A prefix would leak an implementation convention into every call site. The Framework Design Guidelines require PascalCase and no prefix on this surface, so they forbid an s_ prefix on public fields.

See also: VAR-510 (const versus static readonly).

Scope: Public, protected and protected internal static readonly fields (instance fields: NAM-203) · Enforced: IDE1006 · Config: dotnet_naming_rule.nam_213_static_readonly_fields.*, resharper_csharp_naming_rule.static_readonly · Sources: MS-FDG-MEMBERS, MS-FDG-FIELD, MS-IDNAME

NAM-214

DO name a constant field of any accessibility in PascalCase with no prefix (MaxLinesPerOrder, HttpsPort).

✅ Correct

public const int HttpsPort = 443;

internal const int MaxLinesPerOrder = 50;

❌ Incorrect — public constant in camelCase

public const int httpsPort = 443; // Constant must begin with an upper case character

internal const int MaxLinesPerOrder = 50;

Why: A constant never changes and is not state, so it has no scope prefix, and its name appears unchanged in every file and assembly that uses it. Microsoft's identifier rules, the runtime style and the Roslyn style all name constants in PascalCase. Private constants follow the same rule (NAM-215). A local constant is the exception: camelCase is preferred there and PascalCase is accepted (NAM-216). SCREAMING_CASE is not used (NAM-206).

See also: VAR-510 (when to use const).

Scope: Constants (const fields) of every accessibility (private constants: NAM-215); local constants are not covered here (NAM-216) · Enforced: IDE1006 · Config: dotnet_naming_rule.nam_214_constants.*, resharper_csharp_naming_rule.constants, resharper_csharp_naming_rule.private_constants · Sources: MS-IDNAME, MS-FDG-CAPS, RT-STYLE, ROSLYN, RD-NAMING

NAM-215

DO name a private constant in PascalCase with no prefix (MaxRetries).

✅ Correct

private const int MaxRetries = 3;

public static int Retries => MaxRetries;

❌ Incorrect — private constant in camelCase

private const int maxRetries = 3; // Private constant must begin with an upper case character

public static int Retries => maxRetries;

Why: const is not state, so the _ prefix of private fields does not apply to it, and the casing matches public and internal constants (NAM-214). A _maxRetries constant would look like a mutable instance field at the use site. Google style writes private constants in _camelCase, because there "naming convention is unaffected by modifiers such as const".

See also: VAR-510 (when to use const).

Scope: Private constants · Enforced: IDE1006 · Config: dotnet_naming_rule.nam_214_constants.*, resharper_csharp_naming_rule.constants, resharper_csharp_naming_rule.private_constants · Sources: MS-IDNAME, RT-STYLE, ROSLYN, GOOG

NAM-216

CONSIDER naming a local constant in camelCase (const int maxAttempts = 3;); PascalCase (MaxAttempts) is accepted.

✅ Correct

public static int CountAttempts(int failures)
{
    const int maxAttempts = 3;

    return Math.Min(failures, maxAttempts);
}

✅ Accepted — local constant in PascalCase

public static int CountAttempts(int failures)
{
    const int MaxAttempts = 3;

    return Math.Min(failures, MaxAttempts);
}

❌ Incorrect — local constant in SCREAMING_CASE

public static int CountAttempts(int failures)
{
    const int MAX_ATTEMPTS = 3; // SCREAMING_CASE (NAM-206); no tool reports a local constant

    return Math.Min(failures, MAX_ATTEMPTS);
}

Why: A local constant lives in one method body and is read next to the other locals, so camelCase keeps one style in the body and matches the ReSharper default for local constants. The const keyword already tells the reader that the value cannot change. PascalCase is accepted because it is the constant style of Microsoft's identifier rules and the Roslyn style, whose naming rule covers local constants as well as fields. The camelCase preference is a house convention that follows the ReSharper default. IDE1006 cannot accept two styles for one kind of symbol, so the shipped configuration sets the local-constant naming rule to none and ships NAM-216 at none: the build reports neither form, and only ReSharper InconsistentNaming in the editor, which expects camelCase, reports a PascalCase local constant. SCREAMING_CASE is not used (NAM-206).

See also: VAR-511 (declare compile-time constants as const), NAM-214 (constant fields).

Scope: Local constants (const locals) · Enforced: ReSharper: InconsistentNaming in the editor only; no build diagnostic, because the shipped naming rule is set to none · Config: dotnet_naming_rule.nam_216_local_constants.*, resharper_csharp_naming_rule.local_constants · Sources: MS-IDNAME, ROSLYN, RD-NAMING, SA

Parameters

These rules name parameters of every kind and the named arguments that refer to them.

NAM-220

DO name a parameter in camelCase after its meaning rather than its type (orderTotal, customerId, cancellationToken).

✅ Correct

public static decimal ApplyDiscount(decimal orderTotal, decimal discountRate) => orderTotal * (1 - discountRate);

❌ Incorrect — parameter in PascalCase

public static decimal ApplyDiscount(decimal OrderTotal, decimal discountRate) => // Parameter 'OrderTotal' must begin with a lower case character
    OrderTotal * (1 - discountRate);

Why: A parameter name shows in IntelliSense and at every named argument (NAM-227), so it documents the call. orderTotal says what to pass; decimalValue repeats the type the signature already shows. Lower case first letters also separate parameters from properties and types at a glance.

Exceptions: Discard parameters in lambdas ((_, _) => 0) follow NAM-233. Positional record parameters use PascalCase (NAM-221).

Scope: Parameters of methods, constructors, indexers, delegates, lambdas and local functions · Enforced: IDE1006, ReSharper: InconsistentNaming · Config: dotnet_naming_rule.nam_220_parameters.*, resharper_csharp_naming_rule.parameters · Sources: MS-FDG-PARAMS, MS-IDNAME, MS-IDE-NAMING, RD-NAMING

NAM-221

DO name primary-constructor parameters of classes and structs in camelCase and the parameters of positional records in PascalCase, because record parameters become public properties.

C# 12: Primary constructors on classes and structs need C# 12. Positional records exist since C# 9.

✅ Correct

namespace Contoso.Orders;

public sealed class OrderClock(TimeProvider timeProvider)
{
    public DateTimeOffset Now => timeProvider.GetUtcNow();
}

public sealed record ReturnLine(string Sku, int Quantity);

❌ Incorrect — PascalCase class parameter and camelCase record parameter

namespace Contoso.Orders;

public sealed class OrderClock(TimeProvider TimeProvider) // Class parameter must begin with a lower case character
{
    public DateTimeOffset Now => TimeProvider.GetUtcNow();
}

public sealed record ReturnLine(string sku, int Quantity); // Record parameter must begin with an upper case character

Why: A primary constructor parameter on a class or struct is a plain parameter, so it follows NAM-220. A parameter of a positional record declares a public property of the same name, so it follows the property rule (NAM-140). IDE1006 evaluates a record parameter with the property rule and never with the parameter rule, so one .editorconfig enforces both halves.

See also: LANG-012 (when to use a primary constructor).

Scope: Primary-constructor parameters of classes, structs and positional records · Enforced: IDE1006 · Config: dotnet_naming_rule.nam_220_parameters.*, dotnet_naming_rule.nam_140_properties.*, resharper_csharp_naming_rule.parameters, resharper_csharp_naming_rule.property · Sources: MS-IDNAME, MS-CONV, MS-LANG-12, RT-STYLE

NAM-222

DO name a constructor parameter that initializes a field after that field without its _ prefix (trackingNumber initializes _trackingNumber).

✅ Correct

namespace Contoso.Orders;

public sealed class Shipment
{
    private readonly string _trackingNumber;

    public Shipment(string trackingNumber)
    {
        ArgumentException.ThrowIfNullOrWhiteSpace(trackingNumber);
        _trackingNumber = trackingNumber;
    }

    public string Describe() => $"Shipment {_trackingNumber}";
}

❌ Incorrect — parameter carries the field prefix

namespace Contoso.Orders;

public sealed class Shipment(string _trackingNumber) // Prefix '_' is not expected on a parameter
{
    public string Describe() => $"Shipment {_trackingNumber}";
}

Why: The field and the parameter name the same value, so they share a root and differ only by the prefix. In a classic constructor, _trackingNumber = trackingNumber; then needs no this. to tell the two apart (TYPE-014). A parameter that keeps the _ breaks the rule that only fields carry a scope prefix. Roslyn reports it as "Prefix '_' is not expected." The ✅ uses a classic constructor because it validates the argument before storing it; when a parameter is only read, use it directly instead of copying it into a field (LANG-012).

Scope: Constructor and primary-constructor parameters that initialize a field · Enforced: IDE1006 · Config: dotnet_naming_rule.nam_220_parameters.*, resharper_csharp_naming_rule.parameters · Sources: MS-IDNAME, RT-STYLE

NAM-223

DO name the this parameter of an extension method in camelCase after the extended type or its role (this Invoice invoice), never self, obj or @this.

✅ Correct

namespace Contoso.Orders;

public static class InvoiceExtensions
{
    public static bool IsOverdue(this Invoice invoice, DateTimeOffset now) => now > invoice.DueDate;
}

❌ Incorrect — receiver in PascalCase

namespace Contoso.Orders;

public static class InvoiceExtensions
{
    public static bool IsOverdue(this Invoice Invoice, DateTimeOffset now) => // 'this' parameter must begin with a lower case character
        now > Invoice.DueDate;
}

Why: The receiver is read in the body like a local of the extended type, and callers see it as invoice.IsOverdue(now), so it takes the name a local of that type would take. self and @this come from other languages, and obj says nothing about the type. The receiver of a C# 14 extension(...) block follows the same rule (NAM-137).

Scope: The this parameter of classic extension methods · Enforced: IDE1006 · Config: dotnet_naming_rule.nam_220_parameters.*, resharper_csharp_naming_rule.parameters · Sources: MS-FDG-EXT, MS-IDNAME, MS-IDE-NAMING

NAM-224

DO name out, ref, in, ref readonly and scoped parameters in camelCase after their meaning, without a direction prefix such as out, ref or result.

✅ Correct

public static void Swap(ref int first, ref int second) => (first, second) = (second, first);

public static bool TryGetLine(int index, out OrderLine line)
{
    line = new OrderLine("SKU-1", 1, 9.99m);

    return index == 0;
}

public static bool IsPast(in DateTimeOffset dueDate, in DateTimeOffset now) => dueDate < now;

public static long GetTicks(ref readonly DateTimeOffset moment) => moment.UtcTicks;

public static int CountQuantities(scoped ReadOnlySpan<int> quantities) => quantities.Length;

❌ Incorrect — out parameter in PascalCase with a direction prefix

public static bool TryGetLine(int index, out OrderLine OutLine) // Parameter 'OutLine' must begin with a lower case character
{
    OutLine = new OrderLine("SKU-1", 1, 9.99m);

    return index == 0;
}

Why: The modifier (out, ref, in, ref readonly, scoped) already sits next to the name in the signature, and out, ref and in also appear at the call site, so a prefix repeats it and goes stale if the direction changes. Name the value: line, first, moment, quantities.

Scope: out, ref, in, ref readonly and scoped parameters · Enforced: IDE1006 · Config: dotnet_naming_rule.nam_220_parameters.*, resharper_csharp_naming_rule.parameters · Sources: MS-FDG-PARAMDESIGN, MS-FDG-PARAMS, MS-IDE-NAMING

NAM-225

DO name a params parameter with a plural camelCase noun (skus, lines).

✅ Correct

public static int CountSkus(params string[] skus) => skus.Length;

❌ Incorrect — params parameter in PascalCase

public static int CountSkus(params string[] Skus) => // Parameter 'Skus' must begin with a lower case character
    Skus.Length;

Why: A params parameter receives zero or more values, so a plural noun reads correctly in the body (skus.Length, foreach (string sku in skus)). A singular name such as sku suggests that exactly one value arrives. The example uses an array so that it compiles in every C# version. C# 13 also allows params on ReadOnlySpan<T> and other collection types (params ReadOnlySpan<string> skus); the naming rule is the same for all of them.

Scope: params parameters, including C# 13 params collections · Enforced: IDE1006 · Config: dotnet_naming_rule.nam_220_parameters.*, resharper_csharp_naming_rule.parameters · Sources: MS-FDG-PARAMDESIGN, MS-LANG-13, MS-IDE-NAMING

NAM-226

DO name an optional parameter in camelCase like any other parameter, after its meaning, not after its default value.

✅ Correct

public static string PadOrderNumber(string orderNumber, int totalWidth = 10) => orderNumber.PadLeft(totalWidth);

❌ Incorrect — optional parameter in PascalCase

public static string PadOrderNumber(string orderNumber, int TotalWidth = 10) => // Parameter 'TotalWidth' must begin with a lower case character
    orderNumber.PadLeft(TotalWidth);

Why: Callers name optional parameters in named arguments (totalWidth: 3, NAM-227), and the default can change without changing the meaning. A name such as tenWidth or defaultWidth becomes wrong the day the default moves. For when to use optional parameters at all, see TYPE-023.

See also: TYPE-023 (optional parameters versus overloads).

Scope: Optional parameters (when to use them: TYPE-023) · Enforced: IDE1006 · Config: dotnet_naming_rule.nam_220_parameters.*, resharper_csharp_naming_rule.parameters · Sources: MS-FDG-OVERLOAD, MS-IDE-NAMING

NAM-227

DO write a named argument with exactly the parameter name in camelCase (totalWidth: 3), and use named arguments for bool, null and numeric literals whose meaning the call does not show.

✅ Correct

string padded = "7".PadLeft(totalWidth: 3);
Console.WriteLine(padded);

❌ Incorrect — argument name differs from the parameter name, and a bare literal argument

string padded = "7".PadLeft(TotalWidth: 3); // Argument name does not match parameter 'totalWidth' (CS1739)
string unnamed = "7".PadLeft(3); // Literal argument 3 without a name
Console.WriteLine(padded + unnamed);

Why: The compiler matches a named argument to its parameter by exact spelling, case included, and reports CS1739 as an error. The second half of the rule has no tool check: a literal such as true, null or 3 says nothing at the call site, so write orderService.PlaceOrderAsync(customerId: 7, lines, cancellationToken) and PadLeft(totalWidth: 3) instead of PadLeft(3). Reviewers apply that half.

Scope: Named arguments at call sites · Enforced: CS1739 · Sources: MS-IDNAME, GOOG, AV

Locals, lambdas and pattern variables

These rules name local variables, loop variables, lambda parameters, discards, and the variables that deconstruction, patterns, queries, using and catch introduce.

NAM-230

DO name a local variable in camelCase with a noun that says what it holds (orderTotal, shippedOrders), using single letters only for loop counters (NAM-231); a local constant follows NAM-216.

✅ Correct

public static decimal SumTotals(IReadOnlyList<Order> orders)
{
    decimal orderTotal = 0m;
    foreach (Order order in orders)
    {
        orderTotal += order.Total;
    }

    return orderTotal;
}

❌ Incorrect — local in PascalCase

public static decimal SumTotals(IReadOnlyList<Order> orders)
{
    decimal OrderTotal = 0m; // Local must begin with a lower case character
    foreach (Order order in orders)
    {
        OrderTotal += order.Total;
    }

    return OrderTotal;
}

Why: The test for a local name is that a reader can say what it holds without reading its initializer: orderTotal passes, temp and data do not. Lower case first letters separate locals from types, properties and constants in the same body. Single letters stay for loop counters (NAM-231) and one-line lambdas (NAM-232). IDE1006 reports snake_case locals such as line_count through the word separator.

Scope: Local variables, except local constants, which follow NAM-216 (special kinds follow in NAM-231 to NAM-239) · Enforced: IDE1006 checks the first letter and, through the word separator, snake_case such as line_count; it does not check word choice, so reviewers do. It does not check local constants, whose naming rule is set to none (NAM-216) · Config: dotnet_naming_rule.nam_230_locals.*, resharper_csharp_naming_rule.locals · Sources: MS-IDNAME, MS-CONV, MS-IDE-NAMING, RD-NAMING

NAM-231

DO name a for counter i, then j and k for nested loops, and a foreach variable with the singular noun of the element (foreach (OrderLine line in order.Lines)).

✅ Correct — for counter

public static decimal SumByIndex(IReadOnlyList<OrderLine> lines)
{
    decimal total = 0m;
    for (int i = 0; i < lines.Count; i++)
    {
        total += lines[i].Amount;
    }

    return total;
}

✅ Correct — foreach variable

public static decimal SumByLine(IReadOnlyList<OrderLine> lines)
{
    decimal total = 0m;
    foreach (OrderLine line in lines)
    {
        total += line.Amount;
    }

    return total;
}

❌ Incorrect — foreach variable in PascalCase

public static decimal SumByLine(IReadOnlyList<OrderLine> lines)
{
    decimal total = 0m;
    foreach (OrderLine Line in lines) // Loop variable must begin with a lower case character
    {
        total += Line.Amount;
    }

    return total;
}

Why: i, j and k are the conventional counters, and a counter's meaning is its position, so a longer name adds nothing. In foreach the singular noun makes line.Amount read as "the amount of the line". A single letter such as foreach (OrderLine x in lines) tells the reader nothing once the body is longer than one line; reviewers flag it.

See also: VAR-010 (declare loop variables with var; an explicit type is accepted).

Scope: Loop variables of for and foreach · Enforced: IDE1006 · Config: dotnet_naming_rule.nam_230_locals.*, resharper_csharp_naming_rule.locals · Sources: MS-IDNAME, MS-CONV, MS-IDE-NAMING

NAM-232

DO name a lambda parameter in camelCase after the element it represents (order => order.Total), using a single letter only in a lambda that fits on one line and has one parameter.

✅ Correct

public static bool HasLargeOrder(IReadOnlyList<Order> orders, decimal limit) =>
    orders.Any(order => order.Total > limit);

❌ Incorrect — lambda parameter in PascalCase

public static bool HasLargeOrder(IReadOnlyList<Order> orders, decimal limit) =>
    orders.Any(Order => Order.Total > limit); // Lambda parameter must begin with a lower case character

Why: A lambda parameter is a parameter, so it takes camelCase (NAM-220). Naming it after the element (order) lets a reader follow the body without looking up the collection type. A one-parameter lambda that fits on one line, such as numbers.Any(n => n % 2 == 0), may use a single letter because the whole scope is visible at once. Longer lambdas and lambdas with two or more parameters use full names.

Scope: Lambda parameters and anonymous-method parameters · Enforced: IDE1006 · Config: dotnet_naming_rule.nam_220_parameters.*, resharper_csharp_naming_rule.parameters · Sources: MS-CONV, MS-IDE-NAMING, AV

NAM-233

DO use the discard _ for a value you deliberately ignore (out _, _ = dictionary.Remove(key), (_, decimal total)), and never declare a named variable that is assigned but never read.

✅ Correct

public static bool IsQuantity(string text) =>
    int.TryParse(text, System.Globalization.CultureInfo.InvariantCulture, out _);

❌ Incorrect — named variable that is never read

public static void Warm(Func<int> compute)
{
    int unused = compute(); // Value assigned but never read; use a discard
}

Why: A discard states that the value is ignored on purpose, and the compiler keeps no variable for it. A named variable that is never read looks like a mistake, so IDE0059 reports it; with csharp_style_unused_value_assignment_preference = discard_variable the fix offers _. Never declare a variable called _: when one is in scope, _ = x assigns to it instead of discarding.

Exceptions: Lambda parameters you do not use are written _, and (_, _) => is valid for two of them.

Scope: Discards for unused results, out arguments, deconstruction and lambda parameters · Enforced: IDE0059 · Config: csharp_style_unused_value_assignment_preference · Sources: MS-IDE, MS-IDNAME, AV

NAM-234

DO name tuple elements in method signatures, properties and fields in PascalCase ((int Count, decimal Total)), and the variables you deconstruct them into in camelCase (NAM-235).

✅ Correct

public static (int Count, decimal Total) Summarize(IReadOnlyList<OrderLine> lines) =>
    (lines.Count, lines.Sum(line => line.Amount));

❌ Incorrect — tuple elements in camelCase in a signature

public static (int count, decimal total) Summarize(IReadOnlyList<OrderLine> lines) => // Tuple elements in a signature must be PascalCase
    (lines.Count, lines.Sum(line => line.Amount));

Why: In a signature the element names are part of the API: callers read result.Count and result.Total like properties, so they follow the property rule (NAM-140). Variables created by deconstruction are locals and take camelCase (NAM-235). IDE1006 has no symbol kind for tuple elements and no other diagnostic checks their casing, so this is a manual rule that reviewers check (TOOL-018).

See also: VAR-540 (tuples with named elements).

Scope: Tuple element names in signatures and tuple literals · Enforced: Manual · Sources: SA, AV, MS-IDE-NAMING

NAM-235

DO name variables introduced by deconstruction in camelCase ((int count, decimal total) = Summarize(lines);).

✅ Correct

(int count, decimal total) = (3, 9.99m);
Console.WriteLine($"{count} items cost {total}");

❌ Incorrect — deconstructed variable in PascalCase

(int Count, decimal total) = (3, 9.99m); // Deconstructed variable must begin with a lower case character
Console.WriteLine($"{Count} items cost {total}");

Why: Deconstruction declares ordinary locals, so they follow the local rule (NAM-230). Keeping the tuple element names in PascalCase (NAM-234) and the locals in camelCase shows at a glance which side of the = is the API and which is the caller's variable.

See also: VAR-541 (deconstruct into separate locals).

Scope: Variables introduced by deconstruction · Enforced: IDE1006 · Config: dotnet_naming_rule.nam_230_locals.*, resharper_csharp_naming_rule.locals · Sources: AV, MS-IDE-NAMING

NAM-236

DO name pattern variables in camelCase after what they hold (payment is CardPayment card).

✅ Correct

public static bool IsLargeCardPayment(Payment payment, decimal limit) =>
    payment is CardPayment card && card.Amount > limit;

❌ Incorrect — pattern variable in PascalCase

public static bool IsLargeCardPayment(Payment payment, decimal limit) =>
    payment is CardPayment Card && Card.Amount > limit; // Pattern variable must begin with a lower case character

Why: A pattern variable is a local that the pattern declares, so it follows the local rule (NAM-230). Naming it after the matched type or role (card) makes the narrowed use (card.Amount) read as a statement about the card, not about the original payment.

Scope: Pattern variables in is-expressions, switch statements and switch expressions · Enforced: IDE1006 · Config: dotnet_naming_rule.nam_230_locals.*, resharper_csharp_naming_rule.locals · Sources: MS-IDE-NAMING, MS-CONV

NAM-237

DO name LINQ range variables and LINQ lambda parameters with the singular camelCase noun of the element (from order in orders, orders.Where(order => order.IsShipped)).

✅ Correct — method syntax

public static IEnumerable<int> SelectShippedOrderIds(IReadOnlyList<Order> orders) =>
    orders
        .Where(order => order.IsShipped)
        .Select(order => order.Id);

✅ Correct — query syntax

public static IEnumerable<int> SelectShippedOrderIds(IReadOnlyList<Order> orders) =>
    from order in orders
    where order.IsShipped
    select order.Id;

❌ Incorrect — meaningless range variable and numeric suffix

public static IEnumerable<int> SelectShippedOrderIds(IReadOnlyList<Order> orders) =>
    from x in orders // Range variable 'x' does not name the element
    where x.IsShipped
    select x.Id;

public static IEnumerable<int> SelectShippedIds(IReadOnlyList<Order> orders) =>
    orders.Where(o2 => o2.IsShipped).Select(o2 => o2.Id); // Numeric suffix 'o2' does not name the element

Why: In a query the same variable appears in every clause, so a name that matches the collection (orders gives order) states what flows through the pipeline. The test is mechanical: the range variable is the singular of the source collection's name. IDE1006 has no kind for query range variables and no diagnostic checks word choice in lambdas, so this is a manual rule that reviewers check (TOOL-018). Put each query clause on its own line (LANG-051).

Scope: LINQ query range variables and LINQ lambda parameters · Enforced: Manual · Sources: MS-CONV, AV

NAM-238

DO name a variable declared by a using declaration or statement in camelCase after the resource (using var buffer = new MemoryStream();).

✅ Correct

public static long MeasureBufferSize()
{
    using var buffer = new MemoryStream();

    return buffer.Length;
}

❌ Incorrect — using variable in PascalCase

public static long MeasureBufferSize()
{
    using var Buffer = new MemoryStream(); // Using variable must begin with a lower case character

    return Buffer.Length;
}

Why: A using variable is a local that happens to be disposed, so it takes camelCase and a noun for the resource (buffer, stream, connection). PascalCase would make Buffer.Length look like a static member of System.Buffer.

Scope: Variables declared by using declarations and using statements · Enforced: IDE1006 · Config: dotnet_naming_rule.nam_230_locals.*, resharper_csharp_naming_rule.locals · Sources: MS-CONV, MS-IDE-NAMING

NAM-239

DO name the exception variable of a catch clause ex, and omit the variable when the handler does not use it (catch (FormatException)).

✅ Correct

public static string LoadTemplate(string path)
{
    try
    {
        return File.ReadAllText(path);
    }
    catch (IOException ex)
    {
        throw new InvalidOperationException("The order template could not be read.", ex);
    }
}

❌ Incorrect — catch variable in PascalCase

public static string LoadTemplate(string path)
{
    try
    {
        return File.ReadAllText(path);
    }
    catch (IOException Exception) // Catch variable must begin with a lower case character
    {
        throw new InvalidOperationException("The order template could not be read.", Exception);
    }
}

Why: ex is the name Microsoft's samples use most, and a fixed name lets a reader find the exception in a handler without searching. When the handler does not use the exception, leave the variable out: the compiler reports an unused catch variable as warning CS0168. The examples catch an IOException that the caller cannot check for in advance; for input you can check up front, such as typed text that must be a number, use TryParse instead of catching FormatException (ERR-016). e stays reserved for EventArgs parameters, and names such as e or exc for an exception are flagged in review. Microsoft samples use e and exception less often.

Scope: The exception variable of catch clauses · Enforced: IDE1006 · Config: dotnet_naming_rule.nam_230_locals.*, resharper_csharp_naming_rule.locals · Sources: MS-CONV, MS-EXC, MS-IDE-NAMING

Anonymous types and labels

These rules name the members of anonymous types and statement labels.

NAM-240

DO name anonymous-type members in PascalCase, either explicitly (new { OrderId = order.Id }) or by projecting a PascalCase property (new { order.Total }).

✅ Correct

var summary = new { OrderId = 7, Total = 9.99m };
Console.WriteLine(summary.Total);

❌ Incorrect — anonymous-type members in camelCase

var summary = new { orderId = 7, total = 9.99m }; // Anonymous-type members must be PascalCase
Console.WriteLine(summary.total);

Why: The compiler turns each member of an anonymous type into a read-only property, so they follow the property rule (NAM-140). Projecting an existing property (new { order.Total }) keeps its PascalCase name without extra typing, and an explicit name that only repeats the projected name (new { Total = order.Total }) is reported as redundant (LANG-035). IDE1006 has no kind for anonymous-type members, so this is a manual rule that reviewers check (TOOL-018).

See also: LANG-035 (let the compiler infer a member name that matches the projected name), VAR-544 (anonymous types only for local projections).

Scope: Members of anonymous types · Enforced: Manual · Sources: MS-CONV, MS-IDE

NAM-241

DO name a statement label in PascalCase (RetryPayment:) and add a label only where a goto is clearer than a loop or a method (see LANG-061).

✅ Correct

public static int CountScanned(IReadOnlyList<Order> orders, string sku)
{
    int scanned = 0;
    foreach (Order order in orders)
    {
        foreach (OrderLine line in order.Lines)
        {
            scanned++;
            if (line.Sku == sku)
            {
                goto ScanDone;
            }
        }
    }

ScanDone:
    return scanned;
}

❌ Incorrect — label with an underscore and no PascalCase

public static int CountScanned(IReadOnlyList<Order> orders, string sku)
{
    int scanned = 0;
    foreach (Order order in orders)
    {
        foreach (OrderLine line in order.Lines)
        {
            scanned++;
            if (line.Sku == sku)
            {
                goto scan_done;
            }
        }
    }

scan_done: // Label must be PascalCase without underscores
    return scanned;
}

Why: A label is a named jump target. A label takes PascalCase by analogy with method names; no source prescribes label casing. A jump is clearer in one case: leaving nested loops to reach shared exit code, as ScanDone does above. In every other case a return, a break or a loop expresses the flow without a label, and is the first choice (LANG-061). IDE1006 has no label kind and no diagnostic checks label names, so this is a manual rule that reviewers check (TOOL-018).

See also: LANG-061 (goto and labels).

Scope: Statement labels (goto targets) · Enforced: Manual · Sources: RT-STYLE

Sources

The keys cited in this chapter are listed on the Sources page.

MS-IDNAME, MS-CONV, MS-IDE, MS-IDE-NAMING, MS-CA, MS-EXC, MS-FDG-GENERAL, MS-FDG-CAPS, MS-FDG-FIELD, MS-FDG-MEMBERS, MS-FDG-PARAMS, MS-FDG-PARAMDESIGN, MS-FDG-OVERLOAD, MS-FDG-EXT, MS-LANG-12, MS-LANG-13, MS-LANG-14, RT-STYLE, RT-EC, ROSLYN, RD-NAMING, RS-NAMING, RS-NAMING-OPT, SA, AV, GOOG.

Previous: Naming: Types and Members · Home · Next: Variables: Types, Literals and Nullability