C# - hashtable. c# includes hashtable collection in system.collections namespace, which is similar to generic dictionary collection. the hashtable collection stores key-value pairs. it optimizes lookups by computing the hash code of each key and stores it in a different bucket internally and then matches the hash code of the specified key at the time of accessing values.. A hash table is made up of a mapping function and an array. the array contains your data, while the mapping function is used to assign numerical values (keys) to the data. this helps in categorizing the data, which speeds up search times when you search for it. this is, of course, a simplified explanation of a hash table – a real hash table. How to use c# hashtable class hashtable in c# represents a collection of key/value pairs which maps keys to value. any non-null object can be used as a key but a value can. we can retrieve items from hashtable to provide the key . both keys and values are objects. the commonly used functions in hashtable are :.
Now i need to check key = "c" and value= "3" combination is already exits in hashtable or not. hash.containskey value function cheks weather key is exists or not and containsvalue function checks weather value is exists or not.. You can search for a value in an instance of hashtable class using the corresponding key. note that both the key and the value that is stored in a hashtable instance is of the object type. note. C# hashtable class is a collection class where we can store data in the key/value pair. hashtable is not type-safe. hashtable is not generic and both key and value are based on object type. hashtable is used to store unique keys data. if we try to assign value to already used key, it just overrides the previous stored data..
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.