Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>IComparable</code> exposes <a href="http://msdn.microsoft.com/en-us/library/system.icomparable.compareto.aspx" rel="nofollow"><code>CompareTo</code></a>. <code>&lt;</code> and <code>&gt;</code> must be overloaded separately:</p> <pre><code>class Foo : IComparable&lt;Foo&gt; { private static readonly Foo Min = new Foo(Int32.MinValue); private readonly int value; public Foo(int value) { this.value = value; } public int CompareTo(Foo other) { return this.value.CompareTo((other ?? Min).value); } public static bool operator &lt;(Foo a, Foo b) { return (a ?? Min).CompareTo(b) &lt; 0; } public static bool operator &gt;(Foo a, Foo b) { return (a ?? Min).CompareTo(b) &gt; 0; } } </code></pre> <p>I <em>edited</em> the code so that it does not fail when comparing against <code>null</code>. To keep it brief I used a shortcut that works unless <code>value</code> is <code>Int32.MinValue</code> for a proper <code>Foo</code>. Strictly speaking you'd have to check for <code>null</code> explicitly to get <a href="http://msdn.microsoft.com/en-us/library/system.icomparable.compareto.aspx" rel="nofollow">the contract</a> right:</p> <blockquote> <p>By definition, any object compares greater than (or follows) null, and two null references compare equal to each other.</p> </blockquote> <p>Besides, implementing <code>IComparable&lt;T&gt;</code> means that <code>CompareTo(T value)</code> takes a parameter of <code>T</code>. Therefore <code>MyCalendar : IComparable&lt;MyCalender&gt;</code> should implement a method <code>CompareTo(MyCalendar other)</code> rather than <code>PersianDate</code> (or implement <code>IComparable&lt;PersianDate&gt;</code>).</p>
    singulars
    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.
 

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