class Program
{
static void Main(string[] args)
{
Dictionary<string, string> questionDict = new Dictionary<string, List<string>>(); //creating animal dict
List<string> removeKeys = new List<string>(); //so I can remove the keys if need be
questionDict.Add("Does it have whiskers?", "cat");
questionDict.Add("Does it purr?", "cat");
questionDict.Add("Does it bark?", "dog");
while (true)
{
foreach (KeyValuePair<string, string> kvp in questionDict)//checks for each value of kvp in questionDict
{
Console.WriteLine("Computer: {0}", kvp.Key); //prints kvp, or in this instance, the question
string userInput = Console.ReadLine();
if (userInput.ToLower() == "yes") //if yes THEN
{
Console.WriteLine("VAL: {0}", kvp.Value); //writes the value
}
else
{
removeKeys.Add(kvp.Key); //adds the wrong animals to the removeKeys list
}
}
foreach(string rKey in removeKeys)
{
questionDict.Remove(rKey); //removes all the values of rKey in removeKeys from questionDict
}
}
}
}
new Dictionary<string, List<string>>();
是给我的错误。任何帮助?我试图让我的字典每个键有多个值,我被告知只能通过List<string>
来实现。无法隐式转换 'System.Collections.Generic.Dictionary <字符串,System.Collections.Generic.List <string>>' 到 '系统... <字符串,字符串>'
错误的哪部分你不明白?看看那条线的两边。 – SLaks 2015-02-05 21:17:29
那么,你刚刚在同一行上说过你想要一个字典。 –
2015-02-05 21:17:40