3
I need to map a string array to a dictionary
so that I can later test whether an informed string is valid by checking if it is part of the dict
, additionally would like to recover some other information stored on dict
.
For this I am using the following structure:
struct reservedWord
{
public String command;
public type token; //token é um enumerador
};
When trying to store string string through code (modifications trying to follow @mgibsonbr’s recommendations):
Dictionary<string, string> palavras = new Dictionary<string, string>();
for (int i = 0; i < reservedWords.Length; i++)
(...)
palavras.Add(reservedWords[i], word);
at runtime a duplicate key insertion exception is generated. Even when I replace this insertion code with
palavras.Add(reservedWords[i].getHashCode(), word);
I get the same error message.
I understand the mistake you’re making, but don’t understand exactly what you want to do? You have a set of keywords and also another set of words to be tested?
– Miguel Angelo
Exactly that
– user6635