containskey

Dictionary using is custom key but key is always unequal

孤人 提交于 2019-12-23 03:34:06
问题 I am using RTBTextPointer as custom key in dictionary... Init.SpintaxEditorPropertyMain.SpintaxListDict = new Dictionary<RTBTextPointer, SpintaxEditorProperties.SpintaxMappedValue>(new RTBTextPointerComparer()); I worte this RTBTextPointer, and RTBTextPointerComparer classes in class library and using this in different wpf projects, if (Init.SpintaxEditorPropertyMain.SpintaxListDict.ContainsKey(_index) == false) { Init.SpintaxEditorPropertyMain.SpintaxListDict.Add(_index,_SpintaxMappedVal); }

C# List as Dictionary key

让人想犯罪 __ 提交于 2019-12-18 03:57:29
问题 I have a dictionary which is keyed by a List: private Dictionary<List<custom_obj>, string> Lookup; I'm trying to use ContainsKey, but it doesn't seem to be working, and I have no idea why. Here is the debug information from my Visual Studio Immediate Window: ?Lookup.Keys.ElementAt(7)[0] {custom_obj} Direction: Down SID: 2540 ?Lookup.Keys.ElementAt(7)[1] {custom_obj} Direction: Down SID: 2550 searchObject[0] {custom_obj} Direction: Down SID: 2540 searchObject[1] {custom_obj} Direction: Down

C# List as Dictionary key

情到浓时终转凉″ 提交于 2019-12-18 03:57:13
问题 I have a dictionary which is keyed by a List: private Dictionary<List<custom_obj>, string> Lookup; I'm trying to use ContainsKey, but it doesn't seem to be working, and I have no idea why. Here is the debug information from my Visual Studio Immediate Window: ?Lookup.Keys.ElementAt(7)[0] {custom_obj} Direction: Down SID: 2540 ?Lookup.Keys.ElementAt(7)[1] {custom_obj} Direction: Down SID: 2550 searchObject[0] {custom_obj} Direction: Down SID: 2540 searchObject[1] {custom_obj} Direction: Down

C# Dictionary ContainsKey

萝らか妹 提交于 2019-12-10 23:10:04
问题 My problem is ContainsKey is always returning false even when they key has been added and .Equals evaluates to true. I have the following class: public class StatisticsFilter { private String someString1; private String someString2; ..... public override string ToString() { return string.Format("{0}-{1}-{2}-{3}-{4}", someString1, someString2, ...) } public override bool Equals(object obj) { return obj.ToString().Equals(ToString()); } public override int GetHashCode() { return ToString()

Containskey VS Try Catch

一个人想着一个人 提交于 2019-12-10 03:31:56
问题 I have a list of Vector2's Generated I have to check against a dictionary to see if they exist, this function gets executed every tick. which would run fastest/ be better to do it this way? public static bool exists(Vector2 Position, Dictionary<Vector2, object> ToCheck) { try { object Test = ToCheck[Position]; return (true); } catch { return (false); } } Or should I stick with The norm ? public static bool exists(Vector2 Position, Dictionary<Vector2, object> ToCheck) { if (ToCheck.ContainsKey

Dictionary using is custom key but key is always unequal

。_饼干妹妹 提交于 2019-12-09 07:31:24
I am using RTBTextPointer as custom key in dictionary... Init.SpintaxEditorPropertyMain.SpintaxListDict = new Dictionary<RTBTextPointer, SpintaxEditorProperties.SpintaxMappedValue>(new RTBTextPointerComparer()); I worte this RTBTextPointer, and RTBTextPointerComparer classes in class library and using this in different wpf projects, if (Init.SpintaxEditorPropertyMain.SpintaxListDict.ContainsKey(_index) == false) { Init.SpintaxEditorPropertyMain.SpintaxListDict.Add(_index,_SpintaxMappedVal); } everytime containsKey returns false, even it contains, so duplication entry occurs in dictionary.. is

HashMap with byte array key and String value - containsKey() function doesn't work

丶灬走出姿态 提交于 2019-12-09 03:36:43
问题 I'm using a HashMap: byte[] key and String value. But I realize that even I put the same object (same byte array and same string value) by using myList.put(TheSameByteArray, TheSameStringValue) into HashMap, the table still inserts a new object with different HashMapEntry. Then function containsKey() cannot work. Can someone explains this for me? How can I fix this? Thanks. (Android Java) @Override public boolean containsKey(Object key) { if (key == null) { return entryForNullKey != null; }

HashMap with byte array key and String value - containsKey() function doesn't work

雨燕双飞 提交于 2019-12-01 17:36:34
I'm using a HashMap: byte[] key and String value. But I realize that even I put the same object (same byte array and same string value) by using myList.put(TheSameByteArray, TheSameStringValue) into HashMap, the table still inserts a new object with different HashMapEntry. Then function containsKey() cannot work. Can someone explains this for me? How can I fix this? Thanks. (Android Java) @Override public boolean containsKey(Object key) { if (key == null) { return entryForNullKey != null; } int hash = Collections.secondaryHash(key); HashMapEntry<K, V>[] tab = table; for (HashMapEntry<K, V> e =

Java HashMap containsKey returns false for existing object

谁都会走 提交于 2019-11-30 08:08:27
I have a HashMap for storing objects: private Map<T, U> fields = Collections.synchronizedMap(new HashMap<T, U>()); but, when trying to check existence of a key, containsKey method returns false . equals and hashCode methods are implemented, but the key is not found. When debugging a piece of code: return fields.containsKey(bean) && fields.get(bean).isChecked(); I have: bean.hashCode() = 1979946475 fields.keySet().iterator().next().hashCode() = 1979946475 bean.equals(fields.keySet().iterator().next())= true fields.keySet().iterator().next().equals(bean) = true but fields.containsKey(bean) =

Java HashMap containsKey returns false for existing object

百般思念 提交于 2019-11-29 10:43:24
问题 I have a HashMap for storing objects: private Map<T, U> fields = Collections.synchronizedMap(new HashMap<T, U>()); but, when trying to check existence of a key, containsKey method returns false . equals and hashCode methods are implemented, but the key is not found. When debugging a piece of code: return fields.containsKey(bean) && fields.get(bean).isChecked(); I have: bean.hashCode() = 1979946475 fields.keySet().iterator().next().hashCode() = 1979946475 bean.equals(fields.keySet().iterator()