CA1720: Identifiers should not contain type names

Note

This article applies to Visual Studio 2015. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

Item Value
TypeName IdentifiersShouldNotContainTypeNames
CheckId CA1720
Category Microsoft.Naming
Breaking Change Breaking

Cause

The name of a parameter in an externally visible member contains a data type name.

-or-

The name of an externally visible member contains a language-specific data type name.

Rule Description

Names of parameters and members are better used to communicate their meaning than to describe their type, which is expected to be provided by development tools. For names of members, if a data type name must be used, use a language-independent name instead of a language-specific one. For example, instead of the C# type name 'int', use the language-independent data type name, Int32.

Each discrete token in the name of the parameter or member is checked against the following language-specific data type names, in a case-insensitive manner:

  • Bool

  • WChar

  • Int8

  • UInt8

  • Short

  • UShort

  • Int

  • UInt

  • Integer

  • UInteger

  • Long

  • ULong

  • Unsigned

  • Signed

  • Float

  • Float32

  • Float64

    In addition, the names of a parameter are also checked against the following language-independent data type names, in a case-insensitive manner:

  • Object

  • Obj

  • Boolean

  • Char

  • String

  • SByte

  • Byte

  • UByte

  • Int16

  • UInt16

  • Int32

  • UInt32

  • Int64

  • UInt64

  • IntPtr

  • Ptr

  • Pointer

  • UInptr

  • UPtr

  • UPointer

  • Single

  • Double

  • Decimal

  • Guid

How to Fix Violations

If fired against a parameter:

Replace the data type identifier in the name of the parameter with either a term that better describes its meaning or a more generic term, such as 'value'.

If fired against a member:

Replace the language-specific data type identifier in the name of the member with a term that better describes its meaning, a language-independent equivalent, or a more generic term, such as 'value'.

When to Suppress Warnings

Occasional use of type-based parameter and member names might be appropriate. However, for new development, no known scenarios occur where you should suppress a warning from this rule. For libraries that have previous shipped, you might have to suppress a warning from this rule.

CA1709: Identifiers should be cased correctly

CA1708: Identifiers should differ by more than case

CA1707: Identifiers should not contain underscores

CA1719: Parameter names should not match member names