How to add duplicate keys into the Dictionary

后端 未结 6 633
闹比i
闹比i 2021-01-31 17:37

I have some lines from text files that i want to add into the Dictionary.I am using Dictionary for the first time.While adding up starting lines it was Ok but suddenly i got err

6条回答
  •  遇见更好的自我
    2021-01-31 18:29

    Example:

    class Program
            {
                 private static List> d = new List>();
    
                static void Main(string[] args)
                {
                     d.Add(new KeyValuePair("joe", 100));
                     d.Add(new KeyValuePair("joe", 200));
                     d.Add(new KeyValuePair("jim", 100));
                     var result = d.Where(x => x.Key == "joe");
                    foreach(var q in result)
                        Console.WriteLine(q.Value   );
                    Console.ReadLine();
                }
             }
    

提交回复
热议问题