该表达式的类型应为"unit",但类型应为"ConsoleKeyInfo" [英] This expression should have type 'unit', but has type 'ConsoleKeyInfo'
本文介绍了该表达式的类型应为"unit",但类型应为"ConsoleKeyInfo"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只是想在F#控制台应用程序中暂停,所以我写道:
I just wanted to pause in an F# console application, so I wrote:
Console.ReadKey()
Console.ReadKey()
但这会发出警告:This expression should have type 'unit', but has type 'ConsoleKeyInfo'.
该如何解决?
推荐答案
解决方案:
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 _ = ()
这篇关于该表达式的类型应为"unit",但类型应为"ConsoleKeyInfo"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文