Ways of adding items into Hashtable.

Rajesh_Kumar
Posted by Rajesh_Kumar under ASP.NET category on | Points: 40 | Views : 650
We have to imports system.collections namespace.

using System;
using System.Collections;

1st way:-

Hashtable hashtable = new Hashtable();
hashtable[1] = "rajesh";
hashtable[2] = "kumar";
hashtable[3] = "sathua";

foreach (DictionaryEntry entry in hashtable)
{
console.writeline("{0}, {1}", entry.Key, entry.Value);
}


2nd way:-

Hashtable hashtable = new Hashtable();
hashtable.Add("1","rajesh");
hashtable.Add("2","kumar");
hashtable.Add("3","sathua");

Comments or Responses

Login to post response