Quantcast
Channel: SharpDevelop Community
Viewing all articles
Browse latest Browse all 1764

Missing parenthesis in conversion from VB.Net "if" ternary operator

$
0
0

When converting a statement from VB.net to C# including a ternary if operator, the code might not work correctly due to the missing parenthesis:

Original code:

Function test(value As Boolean) As String
    Return "*" & If(value, "Yes", "No") & "*"
End Function

Converted (doesn't compile)

public string test(bool value)
{
    return "*" + value ? "Yes" : "No" + "*";
}

Expected

public string test(bool value)
{
    return "*" + (value ? "Yes" : "No") + "*";
}


Viewing all articles
Browse latest Browse all 1764

Trending Articles