A bit of a rudimentary question, but here goes...
I often use dictionaries to store ancillary information about other objects:
Dictionary<Person, int> timesAccessed;
Person p = // ...;
if (timesAccessed[p] == 0)
// ...
Let's say my 'Person' class just looks like:
class Person
{
public string Name;
}
Note that I haven't implemented Equals
, GetHashCode
, etc. on Person
. Is the dictionary still able to do fast lookups with a key like this? Since Person
is a class, and p
is reference, I can imagine it using the memory address / some internal index as the hash code, but I'd like to be sure that it isn't resorting to a linear scan of the dictionary.