F#序列-如何返回多行 [英] F# Sequences - how to return multiple rows
本文介绍了F#序列-如何返回多行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
let x = [for p in db.ParamsActXes do
if p.NumGroupPar = grp then
yield p.Num, p.Name]
这是我的序列,但问题是它返回了元组列表,我无法访问单个元组元素
Here is my sequence but the problem is it returns the list of tuples, I can't access single tuple element like
let str = "hello" + x.[1]
那是麻烦.
我如何实现这个功能?
推荐答案
要访问2元组的第二个元素,可以使用snd
或模式匹配.因此,如果tup
是2元组,而tup
的第二个元素是字符串,则可以执行以下操作:
To access the second element of a 2-tuple you can either use snd
or pattern matching. So if tup
is a 2-tuple, where the second element of tup
is a string, you can either do:
let str = "hello" + snd tup
或
let (a,b) = tup
let st = "hello" + b
请注意,snd
仅适用于2个元组,而不适用于包含两个以上元素的元组.
Note that snd
only works with 2-tuples, not tuples with more than two elements.
这篇关于F#序列-如何返回多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文