1

当将 Resizable 数组与任何类型一起使用时,我无法遍历该数组,f# 似乎不理解我的预定义类型。这是一个示例代码:

type someData = { 
     Entry:string ; id:int } 
let datas = new ResizeArray<someData>()
let record1 = {someData.Entry = "hiLo" ;someData.id =1234 }
datas.Add(record1)
let record2 = {someData.Entry = "Lolo" ;someData.id =1224 }
datas.Add(record2)
let record3 = {someData.Entry = "Hihi" ;someData.id =1231 }
datas.Add(record3)
let nameOnly = new ResizeArray<string>()
for entries in datas do
    nameOnly.Add(entries.Entry)
4

1 回答 1

0

如果您在

type someData = 
    { Entry:string ; id:int } 

let datas = new ResizeArray<someData>()
let record1 = {someData.Entry = "hiLo" ;someData.id =1234 }
datas.Add(record1)
let record2 = {someData.Entry = "Lolo" ;someData.id =1224 }
datas.Add(record2)
let record3 = {someData.Entry = "Hihi" ;someData.id =1231 }
datas.Add(record3)
let nameOnly = new ResizeArray<string>()

let createEntries () =
    for entries in datas do
        nameOnly.Add(entries.Entry)
createEntries()

没有问题。如果您首先输入代码的一部分直到 for 循环,然后再输入 for 循环,代码也会运行。我认为这与放入交互式临时模块的类型有关。

于 2013-06-05T22:37:19.703 回答