这应该不会太难,但我是 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
}
}
- 1 回答
- 0 关注
- 238 浏览
添加回答
举报
0/150
提交
取消