I'm using a Dictionary<char, ulong>
where the char is a obj no, & ulong is offset.
Now, I need to access the Keys of Dictionary. Keys is any random number which cant predict. I am using VS-2005. I am new to C# so plz provide some code.
I'm using a Dictionary<char, ulong>
where the char is a obj no, & ulong is offset.
Now, I need to access the Keys of Dictionary. Keys is any random number which cant predict. I am using VS-2005. I am new to C# so plz provide some code.
Dictionary provides a Keys property that contains all of the keys in the dictionary.
As Matt says, the Keys
property is your friend. This returns a KeyCollection
, but usually you just want to iterate over it:
foreach (char key in dictionary.Keys)
{
// Whatever
}
Note that the order in which the keys are returned is not guaranteed. In many cases it will actually be insertion order, but you must not rely on that.
I'm slightly concerned that you talk about the keys being random numbers when it looks like they're characters. Have you definitely chosen the right types here?
One more tip - if you will sometimes need the values as well as the keys, you can iterate over the KeyValuePair
s in the dictionary too:
foreach(KeyValuePair<char, ulong> pair in dictionary)
{
char c = pair.Key;
ulong x = pair.Value;
...
}