如何在F#中引用任何大小的元组的特定成员 [英] How can I refer to a specific member of a Tuple of any size in F#

查看:74
本文介绍了如何在F#中引用任何大小的元组的特定成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,这可能是一个愚蠢的问题.

okay, this might be a silly question.

所以我有一些大小为4的元组,例如(int,int,int,int)

So I have some tuples of size 4 so like (int,int,int,int)

如果它是2元组,则可以使用fst(myTuple)来引用第一个元素.我怎么能说一个4元组的第三个元素?

If it were a 2 tuple I could use fst(myTuple) to refer to the first element. How could I, say, refer to the third element of a 4 tuple?

推荐答案

使用模式匹配:

let tup = 1, 2, 3, 4
let _,_,third,_ = tup
printfn "%d" third // displays "3"

这在元组的MSDN文档中直接进行了描述:元组(F#)

This is described directly in the MSDN documentation for tuples: Tuples (F#)

这篇关于如何在F#中引用任何大小的元组的特定成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆