猿问

PromptDialog.Choice 之后的操作

这应该不会太难,但我是 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}



    }


四季花海
浏览 239回答 1
1回答

holdtom

您只需将结果 ( response) 与枚举值进行比较,如下所示:public async Task ChoiceReceivedAsync(IDialogContext context, IAwaitable<booleanChoice> result){&nbsp; &nbsp; booleanChoice response = await result;&nbsp; &nbsp; if (response.Equals(booleanChoice.Yes))&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; //send the inputs to the databse}&nbsp; &nbsp; else&nbsp;&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; //exit or enter the message again&nbsp; &nbsp; }}
随时随地看视频慕课网APP
我要回答