Tutorial :Duplicates in a dictionary then delete or add record



Question:

So I created a dictionary DICTIONARY1

dicFilesDT.Add(dateParts[1], (dateParts[1] + dateParts[2] ));  

so that I would have just the:

KEY as the Date and VALUE as the Date+Time

I need help in making another dictionary (DICTIONARY2) that would

  1. If there are no Duplicates from checking DICTIONARY2 using foreach keyvaluepair in DICTIONARY1 add Key Pair to DICTIONARY2

  2. Check for duplicates of the Key (Date) (thinking ex. dictionary.ContainsKey)

if the dictionary has the KEY then Compare the KEY VALUE from DICTIONARY 1 to DICTIONARY 2 to see which one is larger

ex. 230132 compared to 100425

if DICTIONARY1 KEY VALUE is larger Delete KeyValuePair from DICTIONARY 2 and add DICTIONARY 1 KEY VALUE

else do nothing and continue the loop

Thank you folks for helping me wiht this.


Solution:1

You can't have duplicates in a system.collections.generic.dictionary, it will throw an exception if you try to add a duplicate key.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »