-1
    class MyComparer : IComparable<string>
    {


        public int CompareTo(string second)
        {
            int diff = this.Length - second.Length;
            return ...
        }

    }

That code doesn't work because "MyComparer" does not contain a definiton for "Length", so how to access Length?

Yas
  • 351
  • 2
  • 17

1 Answers1

2

You are implementing the wrong interface. You need IComparer<string> instead:

class MyComparer : IComparer<string>
{
    public int Compare(string x, string y)
    {
        int diff = x.Length - y.Length;

    }
}
Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325