Back to Devexpress

Convert to Constant

coderushforroslyn-115952-refactoring-assistance-convert-to-constant.md

latest1006 B
Original Source

Convert to Constant

  • Aug 03, 2020

Purpose

Converts a variable or field into a constant. Constants are used to store values, which should never change. Use this Refactoring on fields or variables that do not and should not change.

Availability

Available when the cursor is on a field or variable declaration.

Usage

  1. Place the caret on a field or variable declaration.

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

  3. Select Convert to Constant from the menu.

After execution, the Refactoring adds the const modifier to the field or variable declaration.

csharp
private const double g = 9.807;
vb
Private Const g As Double = 9.807

See Also

Make Read-Only

Make Implicit/Explicit