我在玩F#(Visual Studio 2010 beta 1),我寫了一個小小的控制檯腳本,要求用戶輸入2個數字和一個運算符,然後執行它。 它工作正常,除了一個微小的,但煩人的事情:有時我的printfn指令被忽略。我在代碼中放置了斷點來確定情況。F#奇怪的printfn問題
的代碼片段:
let convert (source : string) =
try System.Int32.Parse(source)
with :? System.FormatException ->
printfn "'%s' is not a number!" source;
waitForExitKey();
exit 1
let read =
printfn "Please enter a number.";
System.Console.ReadLine
let num1 : int = read() |> convert // the printfn in the read function is run...
let num2 : int = read() |> convert // ... but here is ignored
這當然不是完整的源代碼,但我認爲那將是足夠的。如果你需要完整的源代碼,請告訴我。
所以我的問題很簡單:什麼導致與printfn這個問題?難道我做錯了什麼?
由於提前, ShdNx
非常感謝!不幸的是,雷更快,所以我接受了他的答案。但我很高興你明確表達了這一點。再次感謝! – ShdNx 2009-06-24 17:43:41