How to print the keys and data of a Hashtable in C#

2 Answers

0 votes
using System;
using System.Collections; 
                      
public class Program
{
    public static void Main()
    {
 		Hashtable ht = new Hashtable(); 
  
        ht.Add("c", "c#"); 
        ht.Add("a", "c++"); 
        ht.Add("d", "java"); 
        ht.Add("e", "c");         
		ht.Add("b", "php"); 
  
        ICollection ic = ht.Keys; 
  
        foreach(string s in ic) {
            Console.WriteLine(s + ": " + ht[s]); 
    	} 
    }
}
  

  
/*
run:
  
a: c++
b: php
c: c#
d: java
e: c
  
*/

 



answered May 10, 2020 by avibootz
0 votes
using System;
using System.Collections; 
                      
public class Program
{
    public static void Main()
    {
 		Hashtable ht = new Hashtable(); 
  
        ht.Add("c", "c#"); 
        ht.Add("a", "c++"); 
        ht.Add("d", "java"); 
        ht.Add("e", "c");         
		ht.Add("b", "php"); 
  
        foreach(DictionaryEntry de in ht) { 
            Console.WriteLine("{0}: {1} ", de.Key, de.Value); 
        } 
    }
}
  

  
/*
run:
  
a: c++ 
b: php 
c: c# 
d: java 
e: c
  
*/

 



answered May 10, 2020 by avibootz

Related questions

1 answer 208 views
1 answer 212 views
212 views asked Feb 20, 2017 by avibootz
1 answer 141 views
141 views asked Feb 20, 2017 by avibootz
2 answers 233 views
3 answers 234 views
...