Questions tagged [containskey]

80 questions
2
votes
2 answers

C# Dictionary ContainsKey

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; …
Luke Belbina
  • 5,708
  • 12
  • 52
  • 75
2
votes
5 answers

What can cause HashMap containsKey() to fail with String as the key?

I'm thoroughly confused by this one. I'm running a full package worth of unit tests. Here's the relevant shared code which gets used by a number of JUnit tests: private static Map jaxbContexts = …
Chris Knight
  • 24,333
  • 24
  • 88
  • 134
2
votes
1 answer

c# weird Dictionary ContainsKey or StringComaprer

It's some kind of weird magic, ContainsKey returns false. I tried to use InvariantCulture comparer with the same result. GameCommands = new Dictionary(StringComparer.Ordinal) { {"Start new game with…
2
votes
1 answer

C#: Using ContainsKey where the keys are objects

Ok so I need a bit of help. I have a generic dictionary "cashdata". The keys of this dictionary are objects (Query objects, a class I have defined). Query objects have "Terms" field, which is a list of strings, and an "Operator" field, which is an…
Wes Field
  • 3,291
  • 6
  • 23
  • 26
2
votes
1 answer

Override Dictionary 's ContainsKey

I have a Dictionary defined like this: public Dictionary Days; Each DateTime is associated to an int. I'd like to have a function which indicates if there is already a DateTime with the same day in my…
user2088807
  • 1,378
  • 2
  • 25
  • 47
1
vote
1 answer

Check key presence in Object in ActionScript?

How to check if specific key is contained in associative array? I know I can loop over all keys but can I do single-step check?
Dims
  • 47,675
  • 117
  • 331
  • 600
1
vote
1 answer

InvalidCastException when calling Dictionary.TryGetValue(String, out object). Why?

I'm at a loss. I have a Dictionary object with String keys. The objects are of a custom type I have. This example throws an InvalidCastException: MyObject temp; if(Dict.TryGetValue("abc", out temp)) //exception If I instead use "ContainsKey", I…
user1214135
  • 625
  • 2
  • 11
  • 22
1
vote
3 answers

How to find values in dictionary in VB

I have this dictionary: Dim chardict As Dictionary(Of Char, Integer) = Nothing chardict.Add("A", 0) chardict.Add("B", 1) I want to do the following if statement but I am a bit stuck on the syntax: if chardict.containskey("A") 'display the value…
K_McCormic
  • 334
  • 2
  • 5
  • 17
1
vote
4 answers

Dictionary ContainsKey does not seem to work with string[] key

I am trying to have a data structure with multiple string keys. To do this, I tried to create a Dictionary with string[] element. But the ContainsKey do no seem to work as I expect: Dictionary aaa = new Dictionary
rizter
  • 25
  • 2
  • 9
1
vote
1 answer

WCF Service reset case sensitive property of Dictionary

i have a Dictionary. it is most important that this dictionary will use its Containskey() method as not case sensitive that is why i use the constructor to make it case insensitive: Dictionary wishProductNames = new…
Rodniko
  • 4,926
  • 20
  • 69
  • 93
1
vote
1 answer

Get an element from a hashmap by == operator, rather than .equal in java

I have a hashmap and I want to find a key by reference. I found out that the get(key) method uses .equal() to find a key. But I need it to use == to find it by reference. For example in the below code: HashMap myMap = new HashMap
nsh
  • 15
  • 1
  • 5
1
vote
2 answers

How can I solve with Java's map containsKey() method?

I checked the code and saving data to the HashMap is correct, when typing ADD. Then after choosing option FIND I can get to the dedicated function but the method is unable to show me found object even if it is correct 100%. Please check this code…
tomeee121
  • 23
  • 2
1
vote
2 answers

Powershell hashtable.containskey is always returning true

The following code is trying to do one thing. Its trying to find IDs that have been added to an Active Directory group since the last time the job was run. It does this by reading the user IDs from an Active Directory group and compares them…
Steve Gray
  • 31
  • 6
1
vote
2 answers

Why is Calendar value different?

I have to count the number of times depending on year, month, day, hour, minute.(second is unified to zero, I don't need second) I chose HashMap as the data structure. HashMap arr_time; If there are same…
현도연
  • 65
  • 1
  • 7
1
vote
4 answers

C# show string once with amount in numbers of the selection in Foreach loop

So i am making a mailfunction and im having an issue showing the data the way i want it to show. This is my code(editted to show only the issue im having): public string Formatsfunction(List mmds) { Dictionary formatNumber…
Senner .P
  • 19
  • 5