I have an object that I want to use to look up other objects. I will be using a Dictionary<TKey, TValue>()
.
The key object has two strings that uniquely identify it, say KeyObj.Str1
and KeyObj.Str2
.
What do you recommend that I use as the key for the dictionary?
1: The concatenation of the strings.
Dictionary<String, TValue>();
Key = KeyObj.Str1:KeyObj.Str2; ("somestring:anotherstring")
2: A unique integer for each object to identify it?
Dictionary<int, TValue>();
KeyObj.ID = _nextID++;
Key = KeyObj.ID;
3: A reference to the object.
Dictionary<KeyObj, TValue>();
Key = KeyObj;
Option 3 would be the easiest, but it seems like it would be inefficient to index a dictionary based on reference values.
If the key object contained a single unique string, the obvious choice would be use that, but having two strings that are only unique in combination makes it more difficult.