What is Hash Table in ASP.NET?
What is the Equivalent of Scripting.Dictionary of Classic ASP?
The Hash Table will look like this inside the memory:
Important points about HashTable
Once you are able to create such a hash table, then you can use it as a datasource.
The KEY field should NOT be NULL. But the value field can be NULL.
System.Collection should be imported. Because it cotains the class "HashTable".
Where exactly I can use HashTable? When you create a DataTable using
an SQL statement, then the DataTable can be directly bind to a Datagrid.
But in certain cases, after fetching the recordset from the Database,
you have to do some arithmetic operation,etc and then only you have to
create a datasource. Under such conditions, HashTable will be useful.
Some useful commands:
int cnt =HashTable1.Count;
HashTable1[ 2222" ] = "ravi";
If 2222 is not there, then a new record will be created.
IDictonaryEnumerator is an interface for Dictonary objects.
IDictionaryEnumerator List1= HashTable1.GetEnumerator();
The above while loop will NOT display the items in the order YOU have entered. Because, the items are stored based on the hash value of the KEY. So HashTable is not good for just displaying all the records. but it works very fast in situations where you will supply the KEY and It will give the VALUE.
What is ListDictionary and HybridDictionary?
HashTable class may be used when the collection is large
Advanced Information on How HashTable works?
When an element is added to the Hashtable, the element is placed into a bucket based on the hash code of the key. Subsequent lookups of the key use the hash code of the key to search in only one particular bucket, thus substantially reducing the number of key comparisons required to find an element. The load factor of a Hashtable determines the maximum ratio of elements to buckets. Smaller load factors cause faster average lookup times at the cost of increased memory consumption. The default load factor of 1.0 generally provides the best balance between speed and size.
A different load factor can also be specified when the Hashtable is created. As elements are added to a Hashtable, the actual load factor of the Hashtable increases. When the actual load factor reaches the specified load factor, the number of buckets in the Hashtable is automatically increased to the smallest prime number that is larger than twice the current number of Hashtable buckets.
Each key object in the Hashtable must provide its own hash function, which can be accessed by calling GetHash. However, any object implementing IHashCodeProvider can be passed to a Hashtable constructor, and that hash function is used for all objects in the table. The capacity of a Hashtable is the number of elements the Hashtable can hold. As elements are added to a Hashtable, the capacity is automatically increased as required through reallocation. The foreach statement of the C# language requires the type of each element in the collection.
Since each element of the Hashtable is a key/value pair, the element type is not the type of the key or the type of the value. Instead, the element type is DictionaryEntry. The foreach statement is a wrapper around the enumerator, which only allows reading from, not writing to, the collection. Because serializing and deserializing an enumerator for a Hashtable can cause the elements to become reordered, it is not possible to continue enumeration without calling the Reset method. Because keys can be inherited and their behavior changed, their absolute uniqueness cannot be guaranteed by comparisons using the Equals method.
The things I learnt while I migrated from classic asp to asp.net is given here for my reference as well as for new beginners.
- The Very First Video Tutorial for ASP.NET C#
- Your First Csharp Code
- PHONE BOOK PROGRAM CODE IN ASP.NET CSHARP
- SINGLE DIMENTIONAL ARRAY C#
- TWO DIMENTIONAL ARRAY C# CODE
- ASP.NET CODING FOR REPEATER CONTROL
- LISTBOX LESSON 2 HOW TO MOVE DATA FROM LISTBOX TO ...
- ASP.NET-CSHARP-DROPDOWNLIST-EDIT FORM-SOURCE CODE
- What is AuotEventWireup and how to use it
- How to Create HyperLink in a Data Grid
- Login Form - Code in ASP.NET Csharp
- What is ADO.NET | Data Provider | DataSet
- CSHARP command parameter concepts
- Why @ symbol is used in string
- ExecuteScalar ExecuteReader ExecuteNonQuery : What...
- HASH TABLE VS SCRIPTING DICTIONARY
- ▼ January (17)
HASH TABLE VS SCRIPTING DICTIONARY
Thanks for Your Visit
|Disclaimer and Copy Right|