Thread: Array Lists - adding keys???

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    38

    Array Lists - adding keys???

    I have an Arraylist of objects - but I want to attach to each object a number (in this case distance of type int). This will be useful for me to sort on the distance value, the shortest to the longest and then do other operations.

    eg.

    OBJECT | INDEX | DISTANCE
    -------------------------------
    fooOject [0] 100
    fooOject [1] 1465
    fooOject [2] 8787
    fooOject [3] 21
    fooOject [4] 66....etc


    Does anyone know how to do this, bearing in mind Im a bit of C# newbie...

  2. #2
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,110
    Why not just implement the distance as a private field from the object class that you would put in the ArrayList ...

    I think you should also be able to somehow work with a HashTable ( distance would then be the value and the object the key ). Then you can still add the objects in an Arraylist but when it comes to sorting on distances you can easily use the HashTable for this...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. adding elements in array
    By reb221 in forum C Programming
    Replies: 6
    Last Post: 12-30-2008, 02:41 PM
  2. question about multidimensional arrays
    By richdb in forum C Programming
    Replies: 22
    Last Post: 02-26-2006, 09:51 AM
  3. Array Program
    By emmx in forum C Programming
    Replies: 3
    Last Post: 08-31-2003, 12:44 AM
  4. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM
  5. Adding objects to an array
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 11-27-2001, 09:24 AM