• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 282
  • Last Modified:

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
0
vernk
Asked:
vernk
1 Solution
 
ColemssCommented:
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now