Error using Binary Search of List

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ThatThatGuy
    Recognized Expert Contributor
    • Jul 2009
    • 453

    Error using Binary Search of List

    How can i search for Rectangle object in a List<T> using BinarySearch() method of List<T>
    .....

    as i'm getting this error failed to compare two elements in a array...

    the program works fine when the List is of Type String but fails when it's any thing other e.g Rectangle

    any help is kindly appreciated
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Have you read the MSDN on BinarySearch?

    Comment

    • ThatThatGuy
      Recognized Expert Contributor
      • Jul 2009
      • 453

      #3
      i had done all sorts of research be it on web or the local msdn.....
      all the examples use String and not any other kind of objects

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        So then you read the MSDN on BinarySearch.
        The error you are getting is explained at the top of the page.

        Originally posted by MSDN
        Exceptions
        Exception type Condition
        InvalidOperatio nException
        The default comparer Comparer.Defaul t cannot find an implementation of the IComparable generic interface or the IComparable interface for type T.

        Remarks
        This method uses the default comparer Comparer.Defaul t for type T to determine the order of list elements. The Comparer.Defaul t property checks whether type T implements the IComparable generic interface and uses that implementation, if available. If not, Comparer.Defaul t checks whether type T implements the IComparable interface. If type T does not implement either interface, Comparer.Defaul t throws an InvalidOperatio nException.

        Comment

        Working...