Javatpoint Logo
Javatpoint Logo

F# Pattern Matching

F# provides pattern matching to match data logically. It is similar to nested if else and switch cases used in C, C++ programming languages. We can apply pattern matching on caonstant values, objects, lists, records, etc.


F# Pattern Matching on Constant Values Example

You can use constant values in pattern matching like given following example.

Output:

You entered 2

F# Pattern Matching using Object Example

You can use objects in pattern to search best match of your input.

Output:

You entered integer value

F# Conditional Pattern Matching Example

Following program shows how to use condinal pattern matching.

Output:

X is greater than y

F# Pattern Matching in list

In F#, you can apply pattern matching in list. Let's see an example.

Output:

3

F# Pattern Matching in Tuples

You can use pattern matching in tuples also. Let's see an example.

Output:

First value is 0 in (0, 1)





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