CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2007
    Posts
    609

    List and order question

    When using Lists, is it safe to assume that when I add an object it will always go at the end, and that the order will always be kept the same? I'm planing on using one in a way where this will be very important. Basically, objects will go in a list and be saved to disk, and be read back in the same order, if the order changes, it will mess things up.

    If this is not save, is there a better collection type to use for something where order is crucial?
    http://www.uovalor.com :: Free UO Server

  2. #2
    Join Date
    Oct 2005
    Location
    Seattle, WA U.S.A.
    Posts
    353

    Re: List and order question

    "... is it safe to assume that when I add an object it will always go at the end, ...

    That would be my assumption predicated on the definition found at
    http://msdn.microsoft.com/en-us/library/3wcytfd1.aspx

  3. #3
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: List and order question

    Quote Originally Posted by ThermoSight View Post
    "... is it safe to assume that when I add an object it will always go at the end, ...

    That would be my assumption predicated on the definition found at
    http://msdn.microsoft.com/en-us/library/3wcytfd1.aspx
    Isn't MSDN cool? Quite often, you can get an answer just by checking out the class description in the docs. It's such a time saver, but yet not many people seem to make it their first stop for looking for info.

  4. #4
    Join Date
    Jul 2007
    Posts
    609

    Re: List and order question

    Often I check something there, and I make an assumption about something which in the end is partially false or there is a factor I don't know about and kicks me in the ***, so that's why I was asking.

    But I'm guessing, it's safe then? There's no factors that could somehow change the order?
    http://www.uovalor.com :: Free UO Server

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: List and order question

    Quote Originally Posted by Red Squirrel View Post
    Often I check something there, and I make an assumption about something which in the end is partially false or there is a factor I don't know about and kicks me in the ***, so that's why I was asking.

    But I'm guessing, it's safe then? There's no factors that could somehow change the order?
    If you read through the List<T> documention, you'll find that a list item can be accessed by index. Would it make sense to access a list item by index if the order changed underneath you?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured