0

Has anyone tried this, have any thoughts on what's the best approach?

I have a Dictionary<SimpleClassContainingOneStringProperty, decimal> and want to compare it against a previous snapshot of the same Dictionary<> object, to check if there has been a change to any of the data within the collection.

1) I can iterate through, running Equals() against each item.

2) I was thinking of using an MD5 checksum on the object.

3) Or, perhaps a way to convert the collection to it's byte representation as a byte[] and then running a simpler, faster equality check against two byte arrays?

Any feedback on these or any other ideas?

Ibraheem
  • 2,168
  • 20
  • 27
  • I would probably flip this on its head. Write a `Dictionary<>` wrapper that flags when a change is made. – itsme86 Aug 06 '18 at 20:13
  • It sounds like you should consider a Merkle or Patricia Trie structure. – Brannon Aug 06 '18 at 20:13
  • This one too: [How to compare two Dictionaries in C#](https://stackoverflow.com/questions/9547351/how-to-compare-two-dictionaries-in-c-sharp) – Jimi Aug 06 '18 at 20:17
  • You should post sample code of what you're trying to accomplish but a Dictionary is inherently one of the fastest collection types in .NET. Arrays are slower than dictionaries; so that plus the conversion would be twice the downgrade. – Michael Puckett II Aug 06 '18 at 20:20

0 Answers0