Fork me on GitHub
TypeName TernaryOperatorAnalyzer (assignment)
Check Id CC0014
Category Style
Severity Warning

Cause

If-else statements can be changed to ternary operators.

Example

var something = true;
string a;
if (something)
{
    a = "a";
}
else
{
    a = "b";
}

Code fix

A code fix will be presented to you that will transform the code:

var something = true;
string a;
a = something ? "a" : "b";

Code fix

Related rules

  • CC0013 - Use ternary operator (return)

See also

TBD