This is being incredibly pedantic, but the closest equivalent of IIf
in C# is
intCurrency = ((Func<bool, object, object, object>)((x, y, z) => x ? y : z))(or.Fields["Currency"].Value == "USD", 100, 0);
However, I wonder if you are really interested in VB's ternary operator. So the following in VB
intCurrency = IIf(or.Fields("Currency").Value = "USD", 100, 0)
could be better written as (notice the difference between IIf
and If
)
intCurrency = If(or.Fields("Currency").Value = "USD", 100, 0)
which is exactly the same in C# as
intCurrency = or.Fields["Currency"].Value == "USD" ? 100 : 0;
Another interesting point is that If
doubles as the null coalescing operator.
Dim text As String = Nothing
text = If(text, "Nothing")
which is exactly the same in C# as
string text = null;
text = text ?? "null";