how to pause the console in F# language

独自空忆成欢 提交于 2019-12-06 18:55:29

问题


Please tell me how I can pause the console window when running the program in F#.

open System
let myList = [0..9]
let myFunction =
for n in myList do
    Console.WriteLine(n)
myFunction

回答1:


I am guessing that you want the console to display the output after the program execution finishes.

You could put this line in the end of your snippet

Console.ReadKey() |> ignore

to 'pause' the console in that sense.




回答2:


// When running in debug mode and using Visual Studio to run the program,  
// one may miss the results as the program runs to the end and exists.  
// Since running normally, i.e. Visual Studio Ctrl-F5, will add an pause
// automatically the pause is only shown when in debug mode.  
let pause () =  
  match System.Diagnostics.Debugger.IsAttached with  
  | true ->  
      printfn "\nPress any key to continue."  
      System.Console.ReadKey(true) |> ignore  
  | false -> ()  

pause ()  



回答3:


You may consider to wrap the pause function in compiler directives, since you probably don't want to have the same effect in release code.

(* your code here *)
#if DEBUG
System.Console.ReadKey(true) |> ignore 
#endif


来源:https://stackoverflow.com/questions/15308268/how-to-pause-the-console-in-f-language

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!