gpt4 book ai didi

c# - Dictionary <字符串,字符串[]>无法将类型 'string[]'隐式转换为 'string'

转载 作者:行者123 更新时间:2023-12-02 11:04:26 24 4
gpt4 key购买 nike

我正在以字典的形式使用所有的字符串数组集合....

字典<(键:主题),(值:字符串数组#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");

我的目标是使用我的类(class):
    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盒子...

我真的不知道

最佳答案

尝试这个 :

public static Dictionary<string, string[]> flags = new Dictionary<string, string[]>()
{
{ "food", l_food };
}
l_food已经是一个 string[]

关于c# - Dictionary <字符串,字符串[]>无法将类型 'string[]'隐式转换为 'string',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21985196/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com