且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

此表达式的类型应为“unit",但类型为“ConsoleKeyInfo"

更新时间:2022-11-30 12:06:35

解决方案:

Console.ReadKey() |> ignore

说明:Console.ReadKey() 返回类型为ConsoleKeyInfo"的对象,但您将其用作语句而不将返回值分配给任何内容.因此,F# 会警告您忽略了一个值.ignore 接受任何类型并且不返回任何内容.可以这样定义:

Explanation: Console.ReadKey() returns an object of type 'ConsoleKeyInfo' but you're using it as a statement without assigning the return value to anything. So F# warns you that you're ignoring a value. ignore takes any type and returns nothing. It could be defined like this:

let ignore _ = ()