Seems like I forgot a typename ... Something inside my head keeps telling me that I have stumbled across a Dictionary that basicly uses a user-defined Comparer for lookups. But I somehow can't find that class in the depths of .Net anymore.
As I have no real idea how to describe what I am looking for without describing a possible implementation, I will also give an example of what I wan't to do.
I am basicly looking for a way to achieve the following (pseudocode):
class CustomId
{
// [...]
}
class Element
{
CustomId id;
}
Container<CustomId, Element> myContainer = new Container(myCustomComparer)
myContainer.Add(new Element()) // No key specified
myElement = myContainer[new CustomId(...)]; // Retrieval with custom id
Maybe this technically isn't quite a dictionary, but I hope the idea is clear. Basicly the key is part of the stored element.
I think you are looking for KeyedCollection<TKey, TItem>
. Create a class that inherits from this class and override the GetKeyForItem()
method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With