Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. ICompareable vs IComparer [modified]

ICompareable vs IComparer [modified]

Scheduled Pinned Locked Moved C#
helpvisual-studioquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rizwan Rathore
    wrote on last edited by
    #1

    Hi All, What are the main differences between these two Interfaces and when we should prefer which one??? and shud we implement these in the same class in which we r comparing or shud we make a new calss for that......also i m having problem implementing IComparer interface when i implement this the compiler gives this error The type or namespace name 'IComparer' could not be found (are you missing a using directive or an assembly reference?) so plz tell me also wots the solution of this Looking forward for help Regards, -- modified at 12:38 Tuesday 23rd May, 2006

    R J 2 Replies Last reply
    0
    • R Rizwan Rathore

      Hi All, What are the main differences between these two Interfaces and when we should prefer which one??? and shud we implement these in the same class in which we r comparing or shud we make a new calss for that......also i m having problem implementing IComparer interface when i implement this the compiler gives this error The type or namespace name 'IComparer' could not be found (are you missing a using directive or an assembly reference?) so plz tell me also wots the solution of this Looking forward for help Regards, -- modified at 12:38 Tuesday 23rd May, 2006

      R Offline
      R Offline
      Robert Rohde
      wrote on last edited by
      #2

      IComparer is defined in System.Collections. Thus you need to add using System.Collections; at the top of your code. IComparable must always be implemented by the the class which should be sorted. IComparer should be implemented in separated classes. You should go with IComparer if you want to sort your objects by different criterias (e.g. by its name, some associated values...). Because IComparer can be separated from the class to be sorted you can have as much implementations as you like.

      1 Reply Last reply
      0
      • R Rizwan Rathore

        Hi All, What are the main differences between these two Interfaces and when we should prefer which one??? and shud we implement these in the same class in which we r comparing or shud we make a new calss for that......also i m having problem implementing IComparer interface when i implement this the compiler gives this error The type or namespace name 'IComparer' could not be found (are you missing a using directive or an assembly reference?) so plz tell me also wots the solution of this Looking forward for help Regards, -- modified at 12:38 Tuesday 23rd May, 2006

        J Offline
        J Offline
        Judah Gabriel Himango
        wrote on last edited by
        #3

        IComparer: something that compares other things IComparable: something that get compared

        Tech, life, family, faith: Give me a visit. I'm currently blogging about: Islamic Domination: Coming to a Jewish state near you! The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups