Ejemplo n.º 1
0
 /// <summary>
 /// Indexer which will allow you to get or set individual values in the dictionary.
 /// </summary>
 /// <param name="key">The key of the value you want to get or set.</param>
 /// <returns>The value stored at the key if there is one.</returns>
 public V this[K key]
 {
     get
     {
         if (data[HashFunction(key)] != null && data[HashFunction(key)].Key.Equals(key))
         {
             return(data[HashFunction(key)].Value);
         }
         else
         {
             throw new KeyNotFoundException("That key does not exist.");
         }
     }
     set
     {
         if (data[HashFunction(key)] == null)
         {
             data[HashFunction(key)] = new CustomPair <K, V>(key, value);
             count++;
         }
         else if (data[HashFunction(key)].Key.Equals(key))
         {
             data[HashFunction(key)] = new CustomPair <K, V>(key, value);
         }
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Adds the specified key and value to the array unless it collides with another key.
 /// </summary>
 /// <param name="key">The key to access the data in the array.</param>
 /// <param name="value">The value to add to the array.</param>
 public void Add(K key, V value)
 {
     if (data[HashFunction(key)] != null && data[HashFunction(key)].Key.Equals(key))
     {
         throw new ArgumentException("That key already exists.");
     }
     else
     {
         data[HashFunction(key)] = new CustomPair <K, V>(key, value);
         count++;
     }
 }