Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. COThat sounds much more like a special-case comparer than like an object implementing `IComparable` properly. Can you come up with a meaningful example where `CompareTo(…) == 0` does **not** imply equality? I certainly can’t. In fact, the interface contract (as per MSDN) **requires** that `CompareTo(…) == 0` implies equality. To put it bluntly, in such a case as yours, use a special `Comparator` object, do *not* implement `IComparable`.
      singulars
    2. CO@Konrad - I did indicate several caveats - that the type doesn't implement IEquatable (so obviously, the originator doesn't want to include an equality test), and that CompareTo results are used for sorting, *not* to evaluate equality. You also get into questions of which equality is relevant (reference, value, ignoring "arbitrary" attributes - a blue book of 500 pages in length may be "equal" to a red book of 500 pages in length, for the purposes of IComparable)
      singulars
    3. COYour last sentence is wrong, and this is the particular mistake I wanted to point out: `IComparable` is wholly inappropriate here. What you’ve got is a very *particular* ordering that only applies in one special situation. For such situations, implementing a general `IComparable` is wrong. This is what `IComparer`s are there for. For example, people cannot be ordered meaningfully. But they *can* be ordered according to their salary, their shoe size, the number of their freckles or their weight. Hence, we would implement different `IComparer`s for all these cases.
      singulars
 

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