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. Hashcodes

Hashcodes

Scheduled Pinned Locked Moved C#
questionalgorithms
6 Posts 5 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.
  • B Offline
    B Offline
    Beringer
    wrote on last edited by
    #1

    Does anybody know a good hashcode algorithm to generate unique codes? What if you have two objects and their properties are equal? How would a hashcode be unique then? Here, I am making an assumption that the hashcode is created using the properties of the control. So I guess the real question is: Is there a way to generate a unique hashcode that doesn't rely on the properties of the object? Thanks Eric

    G D I L B 5 Replies Last reply
    0
    • B Beringer

      Does anybody know a good hashcode algorithm to generate unique codes? What if you have two objects and their properties are equal? How would a hashcode be unique then? Here, I am making an assumption that the hashcode is created using the properties of the control. So I guess the real question is: Is there a way to generate a unique hashcode that doesn't rely on the properties of the object? Thanks Eric

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      Create a hashcode from the reference pointer. --- b { font-weight: normal; }

      1 Reply Last reply
      0
      • B Beringer

        Does anybody know a good hashcode algorithm to generate unique codes? What if you have two objects and their properties are equal? How would a hashcode be unique then? Here, I am making an assumption that the hashcode is created using the properties of the control. So I guess the real question is: Is there a way to generate a unique hashcode that doesn't rely on the properties of the object? Thanks Eric

        D Offline
        D Offline
        Dan Neely
        wrote on last edited by
        #3

        Does the hashcode need to be unique/same across sessions? What're you using it for: uniqueness testing or sorting? If you don't need cross session consistancy or can save the code somehow, and are only using it for uniqueness testing: just give each object a guid.

        1 Reply Last reply
        0
        • B Beringer

          Does anybody know a good hashcode algorithm to generate unique codes? What if you have two objects and their properties are equal? How would a hashcode be unique then? Here, I am making an assumption that the hashcode is created using the properties of the control. So I guess the real question is: Is there a way to generate a unique hashcode that doesn't rely on the properties of the object? Thanks Eric

          I Offline
          I Offline
          Ingo
          wrote on last edited by
          #4

          If you need a unique hashcode that doesn't depend on the properties try the timestamp instead or you can use guid instead of calculating them on your own. Greetings, Ingo

          1 Reply Last reply
          0
          • B Beringer

            Does anybody know a good hashcode algorithm to generate unique codes? What if you have two objects and their properties are equal? How would a hashcode be unique then? Here, I am making an assumption that the hashcode is created using the properties of the control. So I guess the real question is: Is there a way to generate a unique hashcode that doesn't rely on the properties of the object? Thanks Eric

            L Offline
            L Offline
            Le centriste
            wrote on last edited by
            #5

            Be aware that if comparison of instances return true, like in:

            obj1.Equal(obj2) == true

            then they must return the same hashcode.

            obj1.Hahscode() == obj2.hashcode()

            So, if you implement your own hashcode that is unique for every instance, make sure to override the Equal method to always return false. If you don't do that, your class won't be usable in Arrays and Hashtables. -------- "I say no to drugs, but they don't listen." - Marilyn Manson

            1 Reply Last reply
            0
            • B Beringer

              Does anybody know a good hashcode algorithm to generate unique codes? What if you have two objects and their properties are equal? How would a hashcode be unique then? Here, I am making an assumption that the hashcode is created using the properties of the control. So I guess the real question is: Is there a way to generate a unique hashcode that doesn't rely on the properties of the object? Thanks Eric

              B Offline
              B Offline
              Beringer
              wrote on last edited by
              #6

              Thanks for all the suggestions. Much appreciated. Eric

              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