我需要返回列表值并在bot模拟器中显示它们。
private static Dictionary<string, int> Teams;
上面的列表中添加了所有团队名称列表。
代码:
public int GetTeamCount()
{
return Teams.Count;
}
public List<string> GetTeams()
{
var sorted = Teams.OrderBy(p => p.Value);
List<string> orderedTeams = new List<string>();
foreach (var e in sorted)
{
orderedTeams.Add(e.Key);
}
return orderedTeams;
}
以上列表将返回团队名称列表。在模拟器中,当他们要求团队列表时,机器人应该能够返回所有团队名称。
DialogClass.cs:
private async Task ActivityReceivedAsync(IDialogContext context, IAwaitable<object> result)
{
var activity = await result as Activity;
Championships champ = new Championships();
if (activity.Text.Contains("how many teams"))
{
await context.PostAsync($"There are {champ.GetTeamCount()} teams.");
}
else if (activity.Text.Contains("list of team names"))
{
await context.PostAsync($"There are {champ.GetTeams()}");
}
else
{
await context.PostAsync("My responses are limited. Please ask the right questions. ");
}
context.Wait(ActivityReceivedAsync);
}
如何获得以下行显示的团队名称列表?
await context.PostAsync($"There are {champ.GetTeams()}");
答案 0 :(得分:1)
我可以为你写两个可能的回应:
首先:创建以下字符串链接列表:
var teamNames = "";
champ.GetTeams().Foreach(x => teamNames += x + ",");
teamNames.TrimEnd(',');
await context.PostAsync($"There are {teamNames}");
第二:为每个团队名称发送一条消息:
await context.PostAsync("There are:");
champ.GetTeams().Foreach(aync(x) => {
await context.PostAsync(x);
});