How to convert a hashtable to a string in C#

1 Answer

0 votes
using System;
using System.Collections;

class HashTableToString {
    public static void Main() {
        Hashtable ht = new Hashtable();
      
        ht.Add("A", "C");
        ht.Add("B", "Java");
        ht.Add("C", "Python");
        ht.Add("D", "Go");
        ht.Add("E", "Rust");
        ht.Add("F", "TypeScript");

        string s = "";
        IDictionaryEnumerator enumerator = ht.GetEnumerator();
        while (enumerator.MoveNext()) {
            s += enumerator.Key + " ";
            s += enumerator.Value + ", ";
        }
        
        Console.WriteLine("String value: {0}", s);
   }
}



/*
run:

String value: D Go, F TypeScript, A C, E Rust, C Python, B Java, 

*/

 



answered Dec 4, 2025 by avibootz

Related questions

...