Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Based on your comment, you haven't implemented GetHashCode. I'm amazed that the class works at all in a dictionary, unless you're always requesting the <em>identical</em> key that you put in. I would suggest an implementation of something like:</p> <pre><code>public override int GetHashCode() { int hash = 17; hash = hash * 23 + UpperLimit.GetHashCode(); hash = hash * 23 + LowerLimit.GetHashCode(); return hash; } </code></pre> <p>That <em>assumes</em> <code>Double.GetHashCode()</code> gives a consistent value for NaN. There are many values of NaN of course, and you <em>may</em> want to special case it to make sure they all give the same hash.</p> <p>You should also override the <code>Equals</code> method inherited from <code>Object</code>:</p> <pre><code>public override bool Equals(Object other) { return other != null &amp;&amp; other.GetType() == GetType() &amp;&amp; Equals((NumericalRange) other); } </code></pre> <p>Note that the type check can be made more efficient by using <code>as</code> if you seal your class. Otherwise you'll get interesting asymmetries between <code>x.Equals(y)</code> and <code>y.Equals(x)</code> if someone derives another class from yours. Equality becomes tricky with inheritance.</p> <p>You should <em>also</em> make your fields private, exposing them only as propertes. If this is going to be used as a key in a dictionary, I <em>strongly</em> recommend that you make them readonly, too. Changing the contents of a key when it's used in a dictionary is likely to lead to it being "unfindable" later.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload