C#: Remove duplicate values from dictionary?

前端 未结 8 2529
小蘑菇
小蘑菇 2020-12-09 03:28

How can I create a dictionary with no duplicate values from a dictionary that may have duplicate values?

IDictionary myDict = new Dicti         


        
8条回答
  •  情话喂你
    2020-12-09 04:26

    This is how I did it:

                    dictionary.add(control, "string1");
                    dictionary.add(control, "string1");
                    dictionary.add(control, "string2");
                  int x = 0;
            for (int i = 0; i < dictionary.Count; i++)
            {         
                if (dictionary.ElementAt(i).Value == valu)
                {
                    x++;
                }
                if (x > 1)
                {
                    dictionary.Remove(control);
                }
            }
    

提交回复
热议问题