I need help getting this to work. I've got a dictionary object that I need to contain 57 items in. Each item is an int/string pair with the int being an identifier to the string. I'm putting the dictionary in a seperate class file so I don't bloat my main program with too many extra lines of code. I don't want to have any extra files for the user to download.
Since I'm doing it in a class file, I'm trying to simply assign the values to the dictionary like this:
The problem is, I don't know how to assign the values into the dictionary using that method. I would rather stay away from making a method just to populate the dictionary if I can do it this way.
Also, I'm not completely 100% decided on using a dictionary anyway. I basically want an associative array. In PHP this would be easy, since I can have an associative array, but C# makes it difficult.
Can anyone please help me figure this out? If I do go with a dictionary, how would I provide an integer and return the string it's associated with?
Finally, is a Dictionary or a Hashtable better for something like this?
Since I'm doing it in a class file, I'm trying to simply assign the values to the dictionary like this:
Code:
Dictionary<int, string> data = new Dictionary<int, string>()
{
myInt, myString
};
Also, I'm not completely 100% decided on using a dictionary anyway. I basically want an associative array. In PHP this would be easy, since I can have an associative array, but C# makes it difficult.
Can anyone please help me figure this out? If I do go with a dictionary, how would I provide an integer and return the string it's associated with?
Finally, is a Dictionary or a Hashtable better for something like this?
Comment