I’ve been googling for a while now… Ok, I’m sorry, this one is pathetically easy but is there an operator in F# to compare class types, like the ‘is’ keyword in C#? I don’t want to use a full blown match statement or start casting things. Cheers
Share
You can use the
:?construct both as a pattern (insidematch) or as an operator:This behaves slightly differently than in C#, because the compiler still tries to do some checks at compile-time. For example, it is an error to use this if the result would be surely
false:I don’t think this could lead to confusion, but you can always add
boxto convert the argument toobj, which can be tested against any type: