为案例分配回复 [英] Assigning Responses to a Case

查看:104
本文介绍了为案例分配回复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。我想知道是否有办法将某些回复分配给案例陈述。这是我想要做的一个例子;

  switch (e.result.text)
{
case 告诉我一个笑话
synthesizer.speakasync( 为什么鸡过马路? );
break ;

if case == 我不知道
synthesizer.speakasync( 到达另一边);
break ;

else if case ==
synthesizer.speakasync( 猜猜);
break ;
}





是否可以这样做?我已经尝试过很多东西,例如将语音识别引擎变成一个变量并创建新的空白来存储这些响应,但它似乎没有用。

解决方案

< blockquote>由于您使用字符串返回另一个字符串,使用 Dictionary< string,string> 将非常简单,例如



字典<字符串,字符串> response =  new 字典<字符串,字符串>()
{
{ 告诉我一个笑话 鸡为什么交叉道路?},
{ 我不知道 到达另一边},
{ 猜猜},
};


Console.WriteLine( {0}的答案是{1 } 我不知道,响应[ 我不知道]);


Hello. I was wondering if there was a way to assign certain responses to a case statement. This is an example of what I want to do;

switch(e.result.text)
{
    case "Tell me a joke":
        synthesizer.speakasync("Why did the chicken cross the road?");
        break;
        
        if(case == "I don't know")
            synthesizer.speakasync("to get to the other side");
            break;

        else if(case == " ")
            synthesizer.speakasync("Take a Guess");
            break;
}



Is it possible to do this or not? I've tried a lot of things like making the speech recognition engine a variable and creating new voids to store these responses in but it doesn't seem to be working.

解决方案

Since you use a string to return another string, using a Dictionary<string, string> would be pretty straightforward, e.g.

Dictionary<string, string> response = new Dictionary<string, string>()
{
  {"Tell me a joke", "Why did the chicken cross the road?"},
  {"I don't know", "to get to the other side"},
  {" ", "Take a Guess"},
};


Console.WriteLine("The answer to {0} is  {1}", "I don't know", response["I don't know"]);


这篇关于为案例分配回复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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