Composite Key Dictionary
Posted
by AaronLS
on Stack Overflow
See other posts from Stack Overflow
or by AaronLS
Published on 2010-05-20T20:45:19Z
Indexed on
2010/05/20
21:00 UTC
Read the original article
Hit count: 752
c#
|dictionary
I have some objects in List, let's say List<MyClass>
and MyClass has several properties. I would like to create an index of the list based on 3 properties of of MyClass. In this case 2 of the properties are int's, and one property is a datetime.
Basically I would like to be able to do something like:
Dictionary< CompositeKey , MyClass > MyClassListIndex = Dictionary< CompositeKey , MyClass >();
//Populate dictionary with items from the List<MyClass> MyClassList
MyClass aMyClass = Dicitonary[(keyTripletHere)];
I sometimes create multiple dictionaries on a list to index different properties of the classes it holds. I am not sure how best to handle composite keys though. I considered doing a checksum of the three values but this runs the risk of collisions.
© Stack Overflow or respective owner