assign iterator values to unknown key names in hashtable

Posted on 2007-10-05
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 =;

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
Question by:vernk
    LVL 5

    Accepted Solution

    you could

    IDictionaryEnumerator en = oldhshTable.GetEnumerator();
    newhshTable = new hashtable[oldhshTable.count]
    int i = 0;
    while (en.MoveNext())
          string str = en.Value.ToString();
    newhshTable.add(1, str);
    oldhshTable = newhshTable;

    Author Comment

    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())
          string str = en.Key.ToString();

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


    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Suggested Solutions

    Article by: Ivo
    Anonymous Types in C# by Ivo Stoykov Anonymous Types are useful when  we do not need to follow usual work-flow -- creating object of some type, assign some read-only values and then doing something with them. Instead we can encapsulate this read…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now