title: How do I show the hash of a string in a ListBox?
body: <p>I have a project where I have to create my own linear hash, bucket hash and quadratic hash algorithms, so I choose to hash some strings, but I've run into a little problem where I have 2 ListBoxes:</p>
  
  <ul>
  <li>A ListBox full of strings</li>
  <li>A ListBox full of the hashes of those strings</li>
  </ul>
  
  <p>I can print the strings without any problems, but I can't figure out how to print their corresponding hashes into the other ListBox when I click on a button.</p>
  
  <p>Here's my code:</p>
  
  <h1>Form.cs</h1>
  
  <pre><code>private void btnLinearHash_Click(object sender, EventArgs e)
  {
      // Initialize Hash.cs (see below for code)
      Hash.LinearHash linearHash = new Hash.LinearHash();
      RandomArrayGen randGen = new RandomArrayGen();
  
      // Clear both ListBoxes
      lbHashStrings.Items.Clear();
      lbHashesOfStrings.Items.Clear();
  
      for (int i = 0; i &lt; 12; i++)
      {
          // Generate 12 random upper and lowercase strings using RandomArrayGen.cs (see https://pastebin.com/jRsG5r1E)
          lbHashStrings.Items.Add(randGen.GenRandomStrings(12, true, true));
      }
  
      for (int i = 0; i &lt; lbHashStrings.Items.Count; i++)
      {
      // Generate a hash of a string and store it into a Dictionary (see Hash.cs)
      linearHash.GenerateHashOfString(lbHashStrings.Items[i].ToString());
      lbHashesOfStrings.Items.Add(linearHash.FindHashCodeInDictionary(lbHashStrings.Items[i].ToString()));
      }
  }
  </code></pre>
  
  <h1>Hash.cs</h1>
  
  <pre><code>    public class LinearHash
      {
          private Dictionary&lt;byte[], string&gt; linearHashArray = new Dictionary&lt;byte[], string&gt;();
          private byte[] hashCode;
  
          public void GenerateHashOfString(string stringToHash)
          {
              hashCode = Encoding.ASCII.GetBytes(stringToHash);
  
              linearHashArray.Add(hashCode, stringToHash);
          }
  
          public string FindHashCodeInDictionary(string StringToFind)
          {
              byte[] HashOfStringToFind = Encoding.ASCII.GetBytes(StringToFind);
  
              //For some reason, this keeps returning false
              foreach (var keyPairValue in linearHashArray)
              {
                  if ((linearHashArray.ContainsKey(HashOfStringToFind) &amp;&amp; linearHashArray.ContainsValue(StringToFind))
                  {
                      return Encoding.UTF8.GetString(HashOfStringToFind);
                  }
              }
              return "Hash not found";
          }
      }
  </code></pre>
  
  <p>So, my question is: What am I doing wrong? Why is the foreach in Hash.cs returning false?</p>