Home > Code Analysis > Code Issues – Field can be read-only

Code Issues – Field can be read-only

January 23rd, 2011

Cause:

This code issue shows a hint (suggestion) on the fields which can be marked as read-only. When a field declaration includes a readonly modifier, assignments to the fields introduced by the declaration can only occur as part of the declaration or in a constructor (instance or static) in the same class. Read-only fields cannot be changed by other code or the code from team members, thus making it less likely to be messed up by someone who doesn’t understand the purpose of the code.

Sample:

CodeRush Field Can Be Readonly Preview

How to fix:

The Make Read-only refactoring is a code fix for this issue:

CodeRush Make Read-only Fix

—–
Products: CodeRush Pro
Versions: 12.1 and up
VS IDEs: any
Updated: Nov/12/2012
ID: C052

Similar Posts: