f#异常在循环中乱序出现

时间:2015-11-19 19:07:05

标签: f#

在以下功能开始之前是否有显示异常的原因?

let listCharacters (text:string) =
    let stripv3 =  text.Split([|' '|], System.StringSplitOptions.RemoveEmptyEntries) |> System.String.Concat      

    for i in 0..2..stripv3.Length do
            let char = stripv3.Chars(i)
            if char <> ' ' then
                printfn "%c" char  

listCharacters "honey badger is a badass"

产生以下输出: -

System.IndexOutOfRangeException: Index was outside the bounds of the array.
h
n
y
a
g
r
s
b
d
s

有趣的是,如果我按顺序添加try..with内的任何操作,那么为什么会这样做呢?

1 个答案:

答案 0 :(得分:0)

总结上述注释,问题是IDE特有的,而不是语言。

在这种情况下,只能在Visual Studio F#Interactive视图中看到该问题。

完全执行或通过Visual Studio FSI.exe运行时,异常是要输出的最后一项。