title: Creating a unique key (cache key) for multiple parameters
body: <p>I have a method that caches data based on 3 parameters. For example:</p>
  
  <ol>
  <li>state</li>
  <li>age</li>
  <li>number of siblings.</li>
  </ol>
  
  <p>Now I have lots of permutations in my system and they are saved in a dictionary:</p>
  
  <pre><code>Dictionary&lt;string,MyObject&gt; cache;
  </code></pre>
  
  <p>The dictionary's key is a concatination of the three and is done with <code>string.format</code> (something like this):</p>
  
  <pre><code>public string CreateKey(eState state, int age, int numberOfSibilings)
  {
      return string.format("{0}#{1}#{2}", state.ToString(), age.ToString(), numberOfSibilings.ToString());
  }
  </code></pre>
  
  <p><code>eState</code> is an <code>enum(int)</code>.</p>
  
  <p>The <code>CreateKey</code> method is called lots of times and is a performance barrier since <code>string.format</code> isn't extra fast and creating lot's of immutable strings isn't the best this to do.</p>
  
  <p>The key can have empty entries that are replaced with a <code>*</code>. The <code>CreateKey</code> method handles them as it inputs nullables and checks if they have values.</p>
  
  <p>I'm sure there is a better way to do this. And since <code>eState</code> is an <code>int</code>, I thought about creating a key in a faster way with a math formula but I couldn't think about something fast and unique.</p>
  
  <p>Anyway, I'm open for any solution you can offer for creating a unique key as fast and memory friendly as possible.</p>