Code Issues hints for expressions
Here are the code issues for different expressions. If the fix is applied, following a hint it may optimize the code and/or improve its readability.
Null coalescing operation can be used
Cause:
The null coalescing operation verifies the value of a variable for ‘nullness’. If the value is not equal to ‘null’, a variable’s value is returned. If it is equal to ‘null’, a substitute value, provided as a second operand of the operation, is returned. The null coalescing operation simplifies the syntax of the ternary operation, for instance. Converting an expression to a null coalescing operation may be increase code readability.
Sample:
How to fix:
- Apply the Compress to Null Coalescing Operation refactoring:
Redundant String.Format call
Cause:
The String.Format call allows composing a string data, that combines other strings and referenced variable values. If the String.Format call does not take referenced variable values, a simple string concatenation operation or even a single string value can be used instead of String.Format. This may optimize the code and improve its clarify.
Sample:
How to fix:
- Apply the Remove Redundant Call refactoring:
Redundant ToString() call
Cause:
There are cases when the ToString() call is redundant. In these cases, the compiler automatically calls ToString(). If a call ToString() is not required, a hint is shown suggesting you remove it.
Sample:
How to fix:
- Apply the Remove Redundant Call refactoring:
String.Compare can be used
Cause:
Strings can be compared using the equality operator ‘==’. However, this operator performs an exact, case-sensitive comparison of two strings.. For better support of string comparison, the String.Compare call can be used. This code issue of a hint type shows you that the equality operator can be changed into the String.Compare call.
Sample:
How to fix:
- Apply the Use String.Compare refactoring:
String.Format can be used
Cause:
String.Format can process typical strings and variable references. Sometimes, instead of concatenating these pieces with a string concatenation operator, it might be better to use the special String.Format call for this purpose. This may improve code readability and clarity.
Sample:
How to fix:
- Apply the Use String.Format refactoring:
Ternary expression can be used
Cause:
The conditional operator allows you to define a boolean condition and two expressions as a result of a boolean operation. Using the simplified ternary expression can improve code readability, because it allows you to compress if-else statements to a single expression.
Sample:
How to fix:
- Apply the Compress to Ternary Expression refactoring: