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. Other Discussions
  3. The Weird and The Wonderful
  4. Excellent usage Of ComapareTo+Equals methods!!

Excellent usage Of ComapareTo+Equals methods!!

Scheduled Pinned Locked Moved The Weird and The Wonderful
question
1 Posts 1 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.
  • D Offline
    D Offline
    Dan Mos
    wrote on last edited by
    #1
        #region InterfaceImplementation(s)
        public int CompareTo(Project other)
        {
            return this.Description.CompareTo(other.Description);
        }
    
        //use of a very unorthodox Equals+CompareTo methods
        //the project should be unique if either bla or tra is blah
        public bool Equals(Project other)
        {
            return this.PN.Equals(other.PN);
        }
        #endregion
    

    I kid you not. This is eaxctly as my former collegue left it. Including the comments. A further look in the code(where the calss is actualy used) he did something like if(BinnarySearch(currentProj)!=0){ { if ListOfItems.Contains(currentproject) return true; else return false;} else return true;} Instead of doing something like(pseudo kindof only):

    if((descriptionComparer==0) || (PN\_Comparer==0)) {return 0;}
    else if(descriptionComparer<0){return -1;}
    else{return 1;}
    

    inside the CompareTo method. Why??? I guess, that he thought that it will be faster in most cases. As a note, neither myself or my famous former collegue are programmers per say. We're just lazy suns of ... and we did all kind of "apps" to limit the number of phones and/or mails geared toward us from the users. :)

    modified on Sunday, May 2, 2010 9:18 PM

    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