I'm wondering what Data Structure people would recommend to do the following. I have a Class which has three main properties eg.
public class Example {
public Object One { get; }
public Object Two { get; }
public Object Three { get; }
}
Another class contains a collection of these Objects and frequently needs to enumerate over these which I do mainly with LINQ. A lot of the time though I need to lookup/enumerate only a subset of these objects based mainly on the value of property One so what I'd like to do is store these in an efficient data structure based on that property. I could do something like the following:
Dictionary<Object,List<Example>>
But this strikes me as being very inefficient, I know I need some kind of Hash Table but having never used one before in C# I'm unsure of what there is to use.
Some other requirements/notes:
- All the Objects are immutable and have fixed Hash Codes which are computed from the values the class gets instantiated with in the constructors
- Must be able to store multiple items that have the same value (and thus Hash Code) for property One in the same 'slot' in the data structure
- Must be able to freely add and remove Objects from the collection