in C# I could use the keyword 'is'
if (variable is string) { }
how is this done in f#
You can check object type in Java by using the instanceof keyword. Determining object type is important if you're processing a collection such as an array that contains more than one type of object. For example, you might have an array with string and integer representations of numbers.
So all you have to do to see the value and type of a variable in F# Interactive is to just type that variable followed by ;; .
In VB.NET, you need to use the GetType method to retrieve the type of an instance of an object, and the GetType() operator to retrieve the type of another known type. Once you have the two types, you can simply compare them using the Is operator.
Try
if (variable :? string) ...
or
let x = variable :? string
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With