assign iterator values to unknown key names in hashtable

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
vernkAsked:
Who is Participating?
 
ColemssConnect With a Mentor Commented:
you could

IDictionaryEnumerator en = oldhshTable.GetEnumerator();
newhshTable = new hashtable[oldhshTable.count]
int i = 0;
while (en.MoveNext())
{
i++;
      string str = en.Value.ToString();
newhshTable.add(1, str);
}
oldhshTable = newhshTable;
0
 
vernkAuthor 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;

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.