Is it ok to set the key of a dictionary to a reference type? Does the dictionary store the references of those objects or does it store the object instances?
I have a dictionary and I am storing if the lists are loaded or not as a boolean value; If it actually stores the massive lists, It will be troublesome.
public Dictionary<object, bool> isloaded;
It’s perfectly ok – it only stores the reference, not a copy.
However, you have to be careful that after inserting a key object, you don’t change any of the fields of the key object that are used to calculate the key’s GetHashCode().
This is because the object’s GetHashCode() is used to generate the integer key that is used internally as the key. Clearly, if that changes after the key has been inserted, it will be in the wrong place and Bad Things will happen.
(I personally think you should only ever use immutable objects for keys.)