Startsidan  ▸  Texter  ▸  Teknikblogg

Anders Hesselbom

Programmerare, skeptiker, sekulärhumanist, antirasist.
Författare till bok om C64 och senbliven lantis.
Röstar pirat.

Tuples

2010-06-19

Tuples in F# is a list of objects with different types, and the tuple itself is strongly typed. You can imagine a simple class or a structure without having to declare the type. This code creates a tuple called myTuple that contains a string, and integer, another string and finally a boolean.

let myTuple=("A", 10, "B", true)

The string representation of a tuple is a string representation of the individual values within parenthesis. This code…

let myTuple=("A", 10, "B", true)
System.Console.WriteLine(myTuple)

…gives you…

(A, 10, B, True)

This code will extract the individual values from the tuple. The output from this code will be 10.

let myTuple=("A", 10, "B", true)
let v1, v2, v3, v4 = myTuple
System.Console.WriteLine(v2)

The types of the values will be the .NET types from the original values in the tuple, v1 is a string, v2 is a 32 bit integer, v3 is also a string and v4 is a boolean. Tuples can be used in many ways, as allowing a single function to return multiple values.

Categories: Microsoft .NET

Tags: F#

Leave a Reply

Your email address will not be published. Required fields are marked *



En kopp kaffe!

Bjud mig på en kopp kaffe (20:-) som tack för bra innehåll!

Bjud på en kopp kaffe!

Om...

Kontaktuppgifter, med mera, finns här.

Följ mig

Twitter Instagram
GitHub RSS

Public Service

Folkbildning om public service.

Hem   |   linktr.ee/hesselbom   |   winsoft.se   |   80tal.se   |   Filmtips