为了账号安全,请及时绑定邮箱和手机立即绑定

PromptDialog.Choice 之后的操作

PromptDialog.Choice 之后的操作

C#
四季花海 2021-10-24 19:37:11
这应该不会太难,但我是 C# 新手,似乎无法修复它。如果用户希望将输入发送到数据库,我有一个 Prompt.Dialog.Choice 来确认一条消息。我被困在 ChoiceReceivedAsync 中,我想在那里进行操作,无论用户是否回答“是”或“否”,但是我如何在 if-else 语句中调用这些答案?这是相关的代码:public enum booleanChoice { Yes, No }public async Task StartAsync(IDialogContext context)    {        //var message = await result as IMessageActivity;        await context.PostAsync("Do you want you message to be sent?");        PromptDialog.Choice(            context: context,            resume: ChoiceReceivedAsync,            options: (IEnumerable<booleanChoice>)Enum.GetValues(typeof(booleanChoice)),            prompt: " ",            retry: "Please try again.",            promptStyle: PromptStyle.Auto        );    }public async Task ChoiceReceivedAsync(IDialogContext context, IAwaitable<booleanChoice> result)    {        booleanChoice response = await result;        //Here's where I'm stuck:        //if (PromptDialog.Choice == "Yes"){//send the inputs to the databse}        //else (PromptDialog.Choice == "No"){//exit or enter the message again}    }
查看完整描述

1 回答

?
holdtom

TA贡献1805条经验 获得超10个赞

您只需将结果 ( response) 与枚举值进行比较,如下所示:


public async Task ChoiceReceivedAsync(IDialogContext context, IAwaitable<booleanChoice> result)

{

    booleanChoice response = await result;


    if (response.Equals(booleanChoice.Yes))

    {

        //send the inputs to the databse}

    else 

    {

        //exit or enter the message again

    }

}


查看完整回答
反对 回复 2021-10-24
  • 1 回答
  • 0 关注
  • 238 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号