我正在以字典的形式使用一种字符串数组集合,因为......
Dictionary<(key:topic),(value:string array#File.ReadAllLines(#somepath))>
示例:
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:无法隐式转换类型string[]' to
字符串'(CS0029)(SimpleMan)
请注意,这个IDE是MonoDevelop,因为我的笔记本电脑是一个糟糕的2003 linux盒子......
我真的不知道......
答案 0 :(得分:0)
试试这个:
public static Dictionary<string, string[]> flags = new Dictionary<string, string[]>()
{
{ "food", l_food };
}
l_food
已经是string[]
。