Showing posts with label Asp.net Collection Class. Show all posts
Showing posts with label Asp.net Collection Class. Show all posts

Thursday, 28 April 2011

Retrive a Data in arraylist

ArrayList arr = new ArrayList();

 arr = (ArrayList)ViewState["PriceScheme"];

foreach (string Value in arr)
{
               string str = Value.ToString();
}

Add Item into arraylist

ArrayList arr = new ArrayList();
while (dtGetAllPriceScheme.Rows.Count > 0)
{
arr.Add(dtGetAllPriceScheme.Rows[i]["priceScheme"].ToString());
i++;
}
Viewstate["Arr"]=arr

Friday, 24 December 2010

Collection Class

Que:- What�s the .NET datatype that allows the retrieval of data by a unique key?
Ans:- HashTable.

Monday, 20 December 2010

What is Dictionary Generic Class?

Represents a collection of keys and values.
The Dictionary generic class provides a mapping from a set of keys to a set of values. Each addition to the dictionary consists of a value and its associated key. Retrieving a value by using its key is very fast, close to O(1), because the Dictionary class is implemented as a hash table.
The capacity of a Dictionary is the number of elements the Dictionary can hold. As elements are added to a Dictionary, the capacity is automatically increased as required by reallocating the internal array.

Difference between Hashtable vs Dictionary?

  • The Hashtable class and the Dictionary generic class implement the IDictionary interface. The Dictionary generic class also implements the IDictionary generic interface. Therefore, each element in these collections is a key-and-value pair.
  • A Hashtable object consists of buckets that contain the elements of the collection. A bucket is a virtual subgroup of elements within the Hashtable, which makes searching and retrieving easier and faster than in most collections. Each bucket is associated with a hash code, generated using a hash function and based on the key of the element.
  • When an object is added to a Hashtable, it is stored in the bucket that is associated with the hash code that matches the object�s hash code. When a value is being searched for in the Hashtable, the hash code is generated for that value, and the bucket associated with that hash code is searched.
  • The Dictionary class has the same functionality as the Hashtable class. A Dictionary of a specific type (other than Object) has better performance than a Hashtable for value types because the elements of Hashtable are of type Object and, therefore, boxing and unboxing typically occur if storing or retrieving a value type.

What is Hashtable Class?

Represents a collection of key/value pairs that are organized based on the hash code of the key.
Each element is a key/value pair stored in a DictionaryEntry object. A key cannot be a null reference (Nothing in Visual Basic), but a value can be. Key objects must be immutable as long as they are used as keys in the Hashtable.

. What is LinkedList?


LinkedList<T> is a general-purpose linked list. It supports enumerators and implements the ICollection interface, consistent with other collection classes in the .NET Framework.
  • LinkedList<T> provides separate nodes of type LinkedListNode<T>, so insertion and removal are O (1) operations.
  • You can remove nodes and reinsert them, either in the same list or in another list, which results in no additional objects allocated on the heap. Because the list also maintains an internal count, getting the Count property is an O (1) operation.
  • Each node in a LinkedList<T> object is of the type LinkedListNode<T>. Because the LinkedList<T> is doubly linked, each node points forward to the Next node and backward to the previous node. Lists that contain reference types perform better when a node and its value are created at the same time. LinkedList<T> accepts null as a valid Value property for reference types and allows duplicate values.
  • If the LinkedList<T> is empty, the First and Last properties contain null.
  • The LinkedList<T> class does not support chaining, splitting, cycles, or other features that can leave the list in an inconsistent state. The list remains consistent on a single thread. The only multithreaded scenario supported by LinkedList<T> is multithreaded read operations.

Thursday, 17 January 2008

Collections Class

Collections Class  in C#
To construct and manipulate a collection of objects, .Net framework has provided us with many classes. ArrayList, BitArray, HashTable, SortedList, Queue and Stack are some of them. They are all included in System.Collections namespace.

ArrayList
The main problem of traditional arrays is that their size is fixed by the number you specify when declaring the array variable: you cannot add items beyond the specified dimension. Another limitation is that you cannot insert an item inside the list. To overcome this, you can create a linked list. Instead of working from scratch, the .NET Framework provides the

ArrayList class.
With the ArrayList class, you can add new items to a list, insert items inside a list, arrange items of a list, check the existence of an item in a list, remove an item from the list, inquire about the list, or destroy the list. These operations are possible through various properties and methods.

Hashtable
The System.Collections namespace provides a Hashtable container. A Hashtable represents a key/value pair in which the key is used for fast lookup.

BitArray

The BitArray class supports a collection of bits which are represented as Booleans. Because it stores bits rather than objects, BitArray has capabilities different from those of the other collections. However it still supports the basic collection underpinning by implementing ICollection and IEnumerable. It also implements ICloneable.