Code Heaven For C# Developer

Monday, May 17, 2010

Hash Table And ArrayList

CREATE AN ARRAYLIST

The ArrayList object is a collection of items containing a single data value.

Items are added to the ArrayList with the Add() method.

The following code creates a new ArrayList object named mycountries and four items are added:


ArrayList mycountries=New ArrayList();
mycountries.Add("Norway")
mycountries.Add("Sweden")
mycountries.Add("France")
mycountries.Add("Italy")

By default, an ArrayList object contains 16 entries. An ArrayList can be sized to its final size with the TrimToSize() method:


ArrayList mycountries=New ArrayList();
mycountries.Add("Norway")
mycountries.Add("Sweden")
mycountries.Add("France")
mycountries.Add("Italy")
mycountries.TrimToSize()

An ArrayList can also be sorted alphabetically or numerically with the Sort() method:
To sort in reverse order, apply the Reverse() method after the Sort() method:

ArrayList mycountries=New ArrayList();
mycountries.Add("Norway")
mycountries.Add("Sweden")
mycountries.Add("France")
mycountries.Add("Italy")
mycountries.TrimToSize()
mycountries.Sort()
mycountries.Reverse()


CREATE A HASHTABLE

HashTable is a collection that is used to store a value and key pair objects

Hashtable _simpleTable = new Hashtable();


Add some data in it.

_simpleTable.Add("Key1", "Value1");
_simpleTable.Add("Key2", "Value2");


Get the size.


_simpleTable.Count;

Labels:

Wednesday, May 12, 2010

ArrayList And HashTable........

Array List..
1.Array List is a List
2.In this we can only add items to the list
3.Here we Can Add any datatype value,Every item in
arraylist is treated as object

Hash Table..
1.Hash Table is a map
2.Here we can add data with the key
3.Retrieving by key in Hashtable is faster than retrieving in
Arraylist


The ArrayList object is a collection of items containing a single data value.

Labels: