小编Sha*_*azi的帖子

泛型C#出错!

嘿,我是C#的新手(或编程,你可以说,因为我之前只学过html和css)我正在玩仿制药,我做了一本小字典.搜索单词和东西没有问题,但是当我搜索一个与我的单词不匹配的单词时,它会抛出错误,如何解决这个问题请帮忙!

for (int i = 1; i <= 10; i++)
{
    Dictionary<string, string> fivewordDictionary = new Dictionary<string, string>();

    fivewordDictionary.Add("hello", "Saying greeting");
    fivewordDictionary.Add("bye", "Greeting when someone is leaving");
    fivewordDictionary.Add("programming", " I dont even know what it is");
    fivewordDictionary.Add("C#", "An object oriented programming language");
    Console.WriteLine();
    Console.Write("Word: ");

    string userWord = Console.ReadLine();

    Console.WriteLine();

    string s = userWord.ToLower().Trim();

    Console.WriteLine(userWord + ": " + fivewordDictionary[s]);
Run Code Online (Sandbox Code Playgroud)

c# dictionary

1
推荐指数
1
解决办法
106
查看次数

标签 统计

c# ×1

dictionary ×1