Back to Devexpress

Make Read-Only

coderushforroslyn-115554-refactoring-assistance-make-read-only.md

latest1.0 KB
Original Source

Make Read-Only

  • Aug 03, 2020

Purpose

Converts a field to a read-only field. Read-only fields can be initialized either at the declaration or in a constructor, which prevents the field value from the occasional overwriting.

Availability

Available when the cursor is on a field declaration, provided that its value never changes.

Usage

  1. Place the caret on a field declaration.

  2. Press the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions menu.

  3. Select Make Read-Only from the menu.

After execution, the Refactoring adds the readonly modifier to the field declaration.

csharp
private readonly int CustomerID;
vb
ReadOnly Private CustomerID As Integer

See Also

Make Implicit/Explicit

Convert to System Type/Built-In Type