title: How does CompareTo method work while Implementing IComparable?
body: <p>I have a class:</p>
  
  <pre><code> public class Customer :IComparable&lt;Customer&gt;
          {
              public int Id { get; set; }
              public string Name { get; set; }
              public int Salary { get; set; }
          }
  </code></pre>
  
  <p>I also have a List:</p>
  
  <pre><code>Customer cust = new Customer() { Id=10,Name="Jack",Salary= 15000};
              Customer cust1 = new Customer() { Id = 10, Name = "Abby", Salary = 5000 };
              Customer cust2 = new Customer() { Id = 10, Name = "Zed", Salary = 152000 };
  
              List&lt;Customer&gt; CustomerList = new List&lt;Customer&gt;();
              list.Add(cust);
              list.Add(cust1);
              list.Add(cust2);
              CustomerList.Sort();
  </code></pre>
  
  <p>I understand why list.Sort wont work on Customer since Customer class has three properties and it does not know how to sort it. But if I implement the interface <code>IComparable</code> in <code>Customer</code> class I am able to sort the Customer List any way i want. </p>
  
  <pre><code>public class Customer :IComparable&lt;Customer&gt;
          {
              public int Id { get; set; }
              public string Name { get; set; }
              public int Salary { get; set; }
  
              public int CompareTo(Customer other)
              {
                  return this.Salary.CompareTo(other.Salary);
              }            
          }
  </code></pre>
  
  <p>Now my question is.. How does implementing CompareTo method let me sort <code>CustomerList</code>? I am not even overriding Sort Method or anything. 
  I am confused since I have not used CompareTo method at all. </p>
  
  <p>I read <a href="https://stackoverflow.com/a/4188041/2064292">https://stackoverflow.com/a/4188041/2064292</a> but it does not answer my question.</p>