如何修复“不能隐式隐藏类型”? C#中的问题 [英] How do I fix the "cannot implicitly covert type" issue in C#

查看:60
本文介绍了如何修复“不能隐式隐藏类型”? C#中的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到错误消息无法将类型'System.Speech.Synthesis.Prompt'隐式转换为'bool'。



我的代码是:



I am getting the error message, "Cannot implicitly convert type 'System.Speech.Synthesis.Prompt' to 'bool.'"

My code is:

case "quit program"
           bool confirmationResult = speak.SpeakAsync("Are you sure");
           if (confirmationResult)
           {
                  speak.SpeakAsync("Okay");
                  this.close();





ALL THE THE代码:https://codeshare.io/GbeLxj



我尝试过:



我试过制作代码:



ALL OF THE CODE: https://codeshare.io/GbeLxj

What I have tried:

I have tried making the code:

case "quit program"
           bool confirmationResult = Prompt speak.SpeakAsync("Are you sure");
           if (confirmationResult)
           {
                  speak.SpeakAsync("Okay");
                  this.close();



我收到更多错误消息。


I just got more error messages.

推荐答案

查看 SpeechSynthesizer.SpeakAsync Method(String)(System.Speech.Synthesis) [ ^ ]并返回一个Prompt类实例 - 包含要发言的内容的对象。这不会转换为bool,也不会以任何方式获得用户的输入以确认他想要做什么。因此,当您尝试将返回的对象分配给 bool 变量时,系统会抛出它并告诉您我不能这样做,我不知道如何将提示视为布尔值



我认为你需要回到一两个阶段,并弄清楚你的用户应该如何与你的应用程序进行交互 - 因为你需要在那里得到回应,而不是假设奇迹般地提出问题的行为也会得到答案......
Look at the definition of the SpeechSynthesizer.SpeakAsync Method (String) (System.Speech.Synthesis)[^] and it returns a Prompt class instance - "the object that contains the content to speak". That does not convert to a bool, and does not in any way get an input from the user to confirm what he wants to do. So when you try to assign the returned object to your bool variable, the systems throws up it's hands and tells you "I can't do that, I don't known how to treat a Prompt as a Boolean value"

I think you need to go back a stage or two, and work out how your user is supposed to interact with your application - because you need to get a response there rather than assuming that the act of asking a question miraculously also fetches the answer...


这篇关于如何修复“不能隐式隐藏类型”? C#中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆