marco-fiset
marco-fiset

Reputation: 1933

Using TTime as the key of a TDictionary

I want to use TTime as the key of a TDictionary, but I encountered a problem with TTime comparisons and therefore I am seeking for an alternative to this.

My particular problem is that I am trying to build some kind of agenda with the hours on the side, represented with a TTime object and I store them in a TDictionary alongside their top coordinate. Given the hour of the task I want to draw on the grid, I can retrieve its top coordinate easily from the dictionary based on the hour of the tasks. Unfortunately, it does not work because TTime comparisons give unexpected results. I cannot reliably retrieve the coordinate from the dictionary with a TTime.

Upvotes: 2

Views: 448

Answers (1)

Rob Kennedy
Rob Kennedy

Reputation: 163277

The TDictionary constructor accepts an IEqualityComparer<TKey> argument, which it will use for comparing the key values. Implement that interface for TTime (by inheriting from TEqualityComparer) and use SameTime to perform the comparison.

Upvotes: 8

Related Questions