C# 字典无法将类型“string[]”隐式转换为“string”
我正在使用一种字符串数组集合,所有集合都以字典的形式出现,因此 字典 例如:C# 字典无法将类型“string[]”隐式转换为“string”,c#,arrays,string,dictionary,compiler-errors,C#,Arrays,String,Dictionary,Compiler Errors,我正在使用一种字符串数组集合,所有集合都以字典的形式出现,因此 字典 例如: public static Dictionary<string, string[]> flags = new Dictionary<string, string[]>() { { "food", new string[] { l_food }}; } public static string[] l_fo
public static Dictionary<string, string[]> flags = new Dictionary<string, string[]>()
{
{ "food", new string[] { l_food }};
}
public static string[] l_food = File.ReadAllLine(_path + @"..//..//lists/food.txt");
我的目标是利用我的课堂:
public class Algorithms
{
public static string Main(string message)
{
return Get_Response(Get_Topic(message));
}
private string Get_Topic(string message)
{
string[] words = message.Split(' ');
foreach (string word in words)
{
foreach (KeyValuePair<string, string[]> flag in Responses.flags)
{
if (Responses.ignore.Contains(word) == true) ;
else if (flag.Value.ContainsValue(word) == true && Responses.ignore.Contains(word) == false) return flag.Key;
else if (flag.Value.ContainsValue(word) == false && word == " " || word == null) return "afk";
else return "general";
}
}
return null;
}
private string Get_Response(string topic)
{
switch (topic)
{
case "music":
return Set_Response(Responses.r_music);
case "art":
return Set_Response(Responses.r_art);
case "mathmatics":
return Set_Response(Responses.r_mathmatics);
case "military":
return Set_Response(Responses.r_military);
case "technology":
return Set_Response(Responses.r_technology);
case "science":
return Set_Response(Responses.r_science);
case "religion":
return Set_Response(Responses.r_religion);
case "sex":
return Set_Response(Responses.r_sex);
case "wealth":
return Set_Response(Responses.r_wealth);
case "job":
return Set_Response(Reponses.r_job);
case "games":
return Set_Response(Responses.r_games);
case "food":
return Set_Response(Responses.r_food);
case "politics":
return Set_Response(Responses.r_politics);
case "movie":
return Set_Response(Responses.r_movie);
case "general":
return Set_Response(Responses.r_general);
case "afk":
return Set_Response(Responses.r_afk);
}
}
public string Set_Response(string[] topic)
{
return topic[(int)new Random().Next(topic.Length)];
}
}
。。。通过匹配从文本文件加载的字符串数组中未被我的忽略列表删除的可能单词,从用户消息中获取“主题”,即食物
这是一个聊天机器人应用程序,我一直在胡闹,但问题出现时,我看到这一点
错误CS0029:无法隐式转换类型字符串[]“tostring”CS0029 SimpleMan
请注意,这个IDE是MonoDevelop,因为我的笔记本电脑是一个蹩脚的2003 linux机箱
我真的不知道…试试这个:
public static Dictionary<string, string[]> flags = new Dictionary<string, string[]>()
{
{ "food", l_food };
}
l_食品已经是一个字符串[]