Message 1 of 4
Dictionary Says XYZ Key Doesn't Exist When It Does

Not applicable
01-20-2014
02:12 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello
I have a dictionary where the keys are XYZ objects and the values are boolean. I am attempting to check if a key exists in the dictionary.
My Problem: If the dictionary contains the key new XYZ(1,1,1) and I go to check if the dictionary contains this key using myDictionary.ContainsKey(new XYZ(1,1,1) it always returns false.
Why is this happening and how can I fix this? I am aware I am comparing doubles which requires a degree of tolerance but shouldn't the XYZ.Equals() class compensate for this like many other API's that contain vertex classes? Or am I doing something wrong?
Dictionary<XYZ, bool> prevPnts =newDictionary<XYZ, bool>(); prevPnts[new XYZ(1,1,1)]=true;
// Always says the pnt doesnt exist?
if(prevPnts.ContainsKey(new XYZ(1,1,1)))
TaskDialog.Show("Contains");
elseTaskDialog.Show("NOT Contains");