title: Dictionary<TKey, TValue> override Indexer and FindEntry
body: <p>In order to optimize my code, I'm trying to create my own <code>Indexer</code> and my own version of the <code>FindEntry</code> function - so that I can do something like the following within a <code>Dictionary</code>-like class:</p>
  
  <pre><code>object IDictionary.this[int key] {
      get {
          int num = this.FindEntry(key);
          if (num &gt;= 0) {
              return this.entries[num].value;                 
          }
  
          return null;
      }
  
      set {
          Dictionary&lt;TKey, TValue&gt;.VerifyValueType(value);
          this [key] = (TValue)((object)value);
      }
  }
  
  private int FindEntry (int key) {
      if (this.buckets != null) {
          int num = key &amp; 2147483647;
          for (int i = this.buckets[num % this.buckets.Length]; i &gt;= 0; i = this.entries[i].next) {
              if (this.entries[i].hashCode == num &amp;&amp; this.comparer.Equals(this.entries[i].key, key)) {
                  return i;
              }
          }
      }
      return -1;
  }
  </code></pre>
  
  <p>This is useful because my dictionary's key is a struct - but sometimes I have the hashcode rather than the key.</p>
  
  <p>I'm looking for a solution <em>other than</em> rewriting <code>Dictionary&lt;TKey, TValue&gt;</code> from <code>System</code> - but I suspect that may be the only method, because the variable <code>entries</code> within it is private.</p>
  
  <p>Below is a basic example of my code, to help show what I'm trying to accomplish.</p>
  
  <pre><code>struct SuperKey : IEquatable&lt;SuperKey&gt; {
      public int Id;
      public int Environment;
  
      public override int GetHashCode() {
          return this.Id;
      }
  
      public override bool Equals(object other) {
          return other is SuperKey ? Equals((SuperKey)other) : false;
      }
  
      public bool Equals(SuperKey other) {
          return this.Id == other.Id &amp;&amp; this.Environment == other.Environment;
      }
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>class Example {
      Dictionary&lt;SuperKey, Player&gt; players;
  
      void MyFunction() {
          SuperKey sk = new SuperKey(36, 1);
          Player p1 = new Player();
  
          players.Add(sk, p1);
      }
  
      void ReceiveEventForPlayer(int id, PlayerEventName name) {
          ReceiveEventForPlayer(id, 0, name);
      }
  
      void ReceiveEventForPlayer(int id, int environment, PlayerEventName name) {
          Player p = players[new SuperKey(id, 1)];
      }
  
  }
  </code></pre>
  
  <p>In the <code>ReceiveEventForPlayer</code> method just above this, please note the line:</p>
  
  <blockquote>
    <p><code>Player p = players[new SuperKey(id, 1)];</code></p>
  </blockquote>
  
  <p>I would much prefer to be able to use:</p>
  
  <blockquote>
    <p><code>Player p = players[id];</code></p>
  </blockquote>
  
  <p>But this doesn't work... It would actually be <em>most</em> ideal to be able to use <em>either</em> syntax.</p>