Im doing some queries to a active directory, building up my own Dictionary to contain name, phone and email per user.
then i store user to a file, something like this:
domain\groupt\group\user;<checksum>
where path before ; is the unique id for the user (a user can be in different groups so i have to track that) and <checksum> is .GetHashCode() of that Dictinary object for that user.
Then i have a timer that every 30 sec checks AD and builds up the same dictinary for the user and looks up the id and checksum from the file.
BUT this is not working. For some reason .GetHashCode() generates a new int when there is no change to name, phone or email… so im thinking its not the function to use.
so how could i check if a object has changed in the way i tried to describe above?
You may have to override the GetHashCode method of your user object to create your custom one.
Something like
But, anyway comparing the HashCodes only ensures you that the objects are not equal when the result is different, if the hashcodes are the same you still have to check if the contents is the same or not.
HashCode is useful for distributing objects in Hastables, but not for real comparison.
You better implement
IComparableinterface in your classes.