GetHashCode is potentially defined differently for each type, so we can't know by looking at this code what this will return. It's designed to be used in hashing algorithms such as Hashtables and Dictionary objects, as a hashed representation of an object. You probably really don't need to know the "why", but if you want to know the "what", you can see if your type overrides GetHashCode - if it does, then you can check the method out for yourself. If not, then it uses the base class's implementation.
If you use Reflector and check out how GetHashCode is implemented among different types, you'll see some examples - check out System.String and System.Int32 for example - you'll see that they can be simple or very complex. You may also want to check out: http://msdn.microsoft.com/en-us/library/system.object.gethashcode.aspx It's the first article when googling GetHashCode, and it makes for pretty good reading. On Apr 30, 6:28 am, Jamarco <[email protected]> wrote: > Hi guys. > > I have i noob question, but I'm really in trouble if I don't know the > answer. > > Im reading an XNA book (beginning XNA Game Programming - from Novice > to Pro, by the way, is an excelent book) and the author is creating a > "Asteroids" clone. The Player controls a ship and a rain of meteors > fall over the screen, and you have to avoid then. > > My question is: for creating the speed and the position that the > meteor appears on the window, he used a Radom function. When he went > to instantiate the object, he used the following line: > > random = new Random (this.GetHashCode()); > > And I dont know what the GetHashCode function really does. That's why > I'm asking here. > > I'm using this book on a final project in my college in Brazil, so the > questions will rain from the teachers that will going to watch my > lecture. > > Thanks all you guys =) > > PS: forgive my English, im not a native, but i'm trying to do my > best... lol
