Remove unnecessary cast (IDE0004)

Property Value
Rule ID IDE0004
Title Remove unnecessary cast
Category Style
Subcategory Unnecessary code rules
Applicable languages C# and Visual Basic

Overview

This rule flags unnecessary type cast. A cast expression is unnecessary if the code semantics would be identical with or without it. This rule has no associated code style option.

Example

// Code with violations
int v = (int)0;

// Fixed code
int v = 0;
' Code with violations
Dim v As Integer = CType(0, Integer)

' Fixed code
Dim v As Integer = 0

See also