We help IT Professionals succeed at work.

assign iterator values to unknown key names in hashtable

vernk
vernk asked
on
298 Views
Last Modified: 2008-01-09
I need to iterate through a hashtable and assign a value to each key without knowing the key name. I am using C# and  .net framework 2.0



my psuedo code is:

HashTable ht = foo.bar.fields;

for (int i = 1; i < fbfcount; i++)

{
get the name of the key;

assign i to value of key;
}

ending up with a hashtable containing key/value pairs like

ActualKeyName = 1
NextActualKeyName = 2
EtcActualKeyName = 3
Comment
Watch Question

Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
just a note,
thank you for the help, i appreciate it.

 the code you gave needed a little revising, but it taught me what I needed to know.....
below is what I am using

IDictionaryEnumerator en = oldhshTable.GetEnumerator();
            Hashtable newhshTable = new Hashtable();
int i = 0;
while (en.MoveNext())
{
i++;
      string str = en.Key.ToString();

      newhshTable.Add (str, i);
}
oldhshTable= newhshTable;

Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.