这里的东西似乎应该有效,但不是:
let dataSet = new DataSet()
let dataTable1 = dataSet.Tables.Add("Bob")
let dataTable1 = dataSet.Tables.Add("Bilf")
let tableNames = Seq.map (fun (x:DataTable) -> x.TableName) dataSet.Tables
它出现以下错误:
The type 'DataTableCollection' is not compatible with the type 'seq<DataTable>'
尝试手动投射时,同样的错误仍然存在:
let tableNames = Seq.map (fun (x:DataTable) -> x.TableName) (seq<DataTable> dataSet.Tables)
有没有办法在DataTableCollection上执行F#样式的序列操作,还是需要先将DataTableCollection手动转换为F#批准的集合类型?
答案 0 :(得分:5)
您正在寻找Seq.cast
,它正是您所寻找的 - 从IEnumerable
转换为IEnumerable<'t>
dataSet.Tables
|> Seq.cast<DataTable>
|> Seq.map (fun x -> x.TableName)