Home » F# Casting and Conversions

F# Casting and Conversions

by Online Tutorials Library

F# Casting and Conversions

Conversion is a process of converting type of a value to the other required type. It can be primitive or object type.

F# allows casting and conversion of primitive types and object types.


F# Conversion Example

Output:

y = 44  z = 44  

F# Type Casting (Upcasting, and Downcasting) Example

F# allows us to cast object of one type to another type by using :> operator. This operator is used to upcast object. we can downcast object by using :?> operator. We have used these operators in the following program. Let’s see an example.

Output:

BaseClass  DerivedClass  BaseClass  
Next TopicF# Operator

You may also like