我只是想在F#控制台应用程序中暂停,所以我写道:
Console.ReadKey()
但这给出了警告:This expression should have type 'unit', but has type 'ConsoleKeyInfo'.
我该怎么做才能解决此问题?
最佳答案
解:
Console.ReadKey() |> ignore
说明:
Console.ReadKey()
返回“ConsoleKeyInfo”类型的对象,但是您将其用作语句,而没有将返回值分配给任何对象。因此,F#警告您忽略了一个值。 ignore
采用任何类型,不返回任何内容。可以这样定义:let ignore _ = ()
关于f# - 此表达式的类型应该为 'unit',但类型为 'ConsoleKeyInfo',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/324947/