Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine if an object is a certain type in F# [duplicate]

Tags:

in C# I could use the keyword 'is'

if (variable is string) { } 

how is this done in f#

like image 905
phil Avatar asked Aug 23 '13 21:08

phil


People also ask

How do you check if an object is a certain type of object?

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.

How do you determine the type of a variable in F#?

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 ;; .

How to check type of object in vb net?

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.


Video Answer


1 Answers

Try

if (variable :? string) ... 

or

let x = variable :? string 
like image 152
Cᴏʀʏ Avatar answered Sep 24 '22 19:09

Cᴏʀʏ