containskey

Custom Class used as key in Dictionary but key not found

怎甘沉沦 提交于 2019-11-29 09:55:35
I have a class, show below, which is used as a key in a Dictionary<ValuesAandB, string> I'm having issues when trying to find any key within this dictionary, it never finds it at all. As you can see, I have overridden Equals and GetHashCode . To look for the key I'm using ValuesAandB key = new ValuesAandB(A,B); if (DictionaryName.ContainsKey(key)) { ... } Is there anything else that I'm missing? Can anyone point out what I'm doing wrong? private class ValuesAandB { public string valueA; public string valueB; // Constructor public ValuesAandB (string valueAIn, string valueBIn) { valueA =

C# List as Dictionary key

孤街浪徒 提交于 2019-11-29 03:13:57
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 SID: 2550 ?Lookup.ContainsKey(searchObject) false In my common sense, that last ContainsKey should be

Custom Class used as key in Dictionary but key not found

こ雲淡風輕ζ 提交于 2019-11-28 03:19:36
问题 I have a class, show below, which is used as a key in a Dictionary<ValuesAandB, string> I'm having issues when trying to find any key within this dictionary, it never finds it at all. As you can see, I have overridden Equals and GetHashCode . To look for the key I'm using ValuesAandB key = new ValuesAandB(A,B); if (DictionaryName.ContainsKey(key)) { ... } Is there anything else that I'm missing? Can anyone point out what I'm doing wrong? private class ValuesAandB { public string valueA;