According to this answer, I can match against DateTime.MinValue like this:
let result =
match date with
| d when d = DateTime.MinValue -> 1
| _ -> 0
How do I do this, if I have a match like this?
let result =
match (startDate, endDate) with
This doesn’t work:
let result =
match (startDate, endDate) with
| d when d = DateTime.MinValue, e when e = DateTime.MinValue -> 0
Compiler error for the second when:
Unexpected keyword 'when' in pattern matching. Expected '->' or other token.
>Solution :
when can be added to a whole pattern, not to nested patterns, so you need something like this:
match (startDate, endDate) with
| d, e when d = DateTime.MinValue && e = DateTime.MinValue -> 0
| _ -> 1
Note that in this case, pattern matching is not really necessary, and you can go for a simpler if:
if d = DateTime.MinValue && e = DateTime.MinValue then
0
else
1