using System;
using System.Collections;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Hashtable empTable = new Hashtable();
empTable.Add("1", "Raj");
empTable.Add("2", "James");
empTable[3]= "Shiva";
foreach (DictionaryEntry obj in empTable)
Console.WriteLine("\t{0}:\t{1}", obj.Key, obj.Value);
Console.ReadLine();
}
}
}
Property | Description |
---|---|
Capacity | Gets or sets the number of elements in the SortedList |
Count | Gets the number of elements contained in the SortedList. |
IsFixedSize | It returns Boolean value. True- if the size is Fixed, else False. |
Item | Gets or sets the element at the specified key in the SortedList. |
Keys | Get list of keys of SortedList. |
Values | Get list of values in SortedList |
Methods | Description |
---|---|
void Add(object key, object value) | Add key-value pairs into SortedList. |
void Remove(object key) | Removes item from SortedList according to key. |
void RemoveAt(int index) | Removes item at the specified index. |
bool Contains(object key) | Checks whether key exists or not in SortedList. |
object GetByIndex(int index) | Returns the item specified by index |
int IndexOfKey(object key) | Returns an index of specified key |
using System;
using System.Collections;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
SortedList list = new SortedList();
list.Add(3, "Third");
list.Add(4, "Fourth");
list.Add(1, "First");
list.Add(5, "Fifth");
list.Add(2, "Second");
foreach(DictionaryEntry obj in list)
{
Console.WriteLine("\t{0}:\t{1}", obj.Key, obj.Value);
}
Console.WriteLine("Capacity =: " +list.Capacity);
Console.WriteLine("Count =: " +list.Count);
Console.WriteLine("ContainsKey =: " + list.ContainsKey(3));
Console.WriteLine("ContainsValue =: " + list.ContainsValue(3));
Console.WriteLine("GetByIndex =: " + list.GetByIndex(1));
Console.WriteLine("IndexOfKey =: " + list.IndexOfKey(2));
Console.WriteLine("IndexOfValue =: " + list.IndexOfValue("Third"));
Console.WriteLine("IsFixedSize =: " + list.IsFixedSize);
Console.ReadLine();
}
}
}
SortedList list = new SortedList();
list.Add(2, "Second");
// It will give run time exception. Item has already been added. Key in dictionary:2
list.Add(2, "MyValue");
using System;
using System.Collections;
using System.Collections.Specialized;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
ListDictionary list = new ListDictionary();
list.Add(3, "Third");
list.Add(4, "Fourth");
list.Add(1, "First");
list.Add(5, "Fifth");
list.Add(2, "Second");
foreach(DictionaryEntry obj in list)
{
Console.WriteLine("\t{0}:\t{1}", obj.Key, obj.Value);
}
Console.WriteLine("Count =: " + list.Count);
Console.WriteLine("IsFixedSize =: " + list.IsFixedSize);
Console.ReadLine();
}
}
}
using System;
using System.Collections;
using System.Collections.Specialized;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
HybridDictionary list = new HybridDictionary();
list.Add(1, "First");
list.Add(2, "Second");
list.Add(3, "Third");
list.Add(4, "Fourth");
list.Add(5, "Fifth");
foreach(DictionaryEntry obj in list)
{
Console.WriteLine("\t{0}:\t{1}", obj.Key, obj.Value);
}
Console.WriteLine("Count =: " + list.Count);
Console.ReadLine();
}
}
}