Conditional Operator in F# (A?B:C)

489 views Asked by At

In C#, we have the conditional operator:

[condition] ? [value if true] : [value if false]

But I can't seem to find this in F#. Does it exist?

1

There are 1 answers

1
MeanGreen On BEST ANSWER

As found here the answer is

C# has the ternary operator "?:" for conditional expressions:

condition ? trueVal : falseVal 

F# has the same operator, but its name is if-then-else:

if condition then trueVal else falseVal

(Note that "if" is used much less frequently in F# than in C#; in F#, many conditionalexpressions are done via pattern-matching rather than if-then-else.)

The website I linked offers a bunch of C# vs F# examples.