【发布时间】:2014-02-24 10:33:21
【问题描述】:
我正在使用一种字符串数组集合,所有这些集合都以字典的形式......
字典
例子:
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[]' tostring' (CS0029) (SimpleMan)
请注意,这个 IDE 是 MonoDevelop,因为我的笔记本电脑是一个蹩脚的 2003 linux 机器......
我真的不知道...
【问题讨论】:
标签: c# arrays string dictionary compiler-errors