字典包含列表地址而不是列表值C#

Nik*_*sov 0 c# dictionary for-loop list

我正在尝试创建一个程序,其中包含一个带有单词的字典,它们的定义用':'分隔,每个单词用'|'分隔 但出于某种原因,当我打印字典的值时,我得到了System.Collection.Generic.List

这是一个可能的输入:"解决:任务或运动所需的设备|代码:为计算机程序编写代码|位:小块,部分或数量的东西|处理:坚决努力处理问题|位:短时间或距离"

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ex1_Dictionary
{
    class Program
    {
        static void Main(string[] args)
        {
            var Input = Console.ReadLine().Split(':', '|').ToArray();
            var Words = new List<string>();
            var Dict = new Dictionary<string, List<string>>();
            for (int i = 0; i < Input.Length; i+=2)
            {
                string word = Input[i];
                string definition = Input[i + 1];
                word = word.TrimStart();
                definition = definition.TrimStart();
                Console.WriteLine(definition);
                if (Dict.ContainsKey(word) == false)
                {
                    Dict.Add(word, new List<string>());
                }
                Dict[word].Add(definition);
            }
            foreach (var item in Dict)
            {
                Console.WriteLine(item);
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

Ren*_*ogt 5

我实际上期望输出是一个KeyValuePair<string, List<string>>,因为这就像你在行中那样item迭代时所得到Dictionary<string, List<string>>

foreach(var item in Dict)
Run Code Online (Sandbox Code Playgroud)

您应该将输出更改为:

Console.WriteLine(item.Key + ": " + string.Join(", " item.Value)); 
Run Code Online (Sandbox Code Playgroud)