Storing Hash128 as a readonly instance variable breaks hash calculation

Viewed 51

I have code that looks like this:

public class HashWrapper {
  private readonly Hash128 hash;

  public HashWrapper() {
    this.hash = new Hash128();
  }

  public HashWrapper Append(String val) {
    this.hash.Append(val);
    return this;
  }

  public override string ToString() {
    return this.hash.ToString();
  }
}

The following code produces a hash string with all 0s:

new HashWrapper().Append("Hello").ToString();

However, if I use Hash128 directly I get the correct value: var hash = new Hash128(); hash.Append("Hello"); hash.ToString();

Any ideas why this would happen? It seems like Hash128 doesn't like being heap allocated?

0 Answers
Related