Javatpoint Logo
Javatpoint Logo

F# Reference Cells

Reference cells refer to memory locations. It allows you to create mutable values. F# uses immutable data structure by default.

You can create reference cells by using ref operator. It holds actual value.

Reference cells can be dereferenced by using! (Bang) operator. It uses : = operator to assign new value.

Syntax:


F# Reference Cells Example

Output:

50

F# Reference Cells Example2

Output:

50
100

F# Reference Cells Value Property and Contents Field Example

Output:

101
102

F# Reference Cells vs. Mutable Variables

Reference cells and mutable variables both can be used in all situations except that compiler does not allow to use mutable variables in lambda expressions, sequence expressions etc. In such scenario, you can use reference cells.

Next TopicF# Structures





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA