如何在 F# 中引用任意大小的元组的特定成员 [英] How can I refer to a specific member of a Tuple of any size in F#
本文介绍了如何在 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屋!
查看全文