Order of Items in a collection object

  • Thread starter Thread starter Sugandh Jain
  • Start date Start date
S

Sugandh Jain

Hi,

I am developing using MS Visual Studio .net 2005, c# 2.0.

My query/confusion is as follows:

If I have a collection of a particular type of object.

While moving in the collection using foreach or forloop, will I get the
taxlots in the same order in which they were inserted into the collection.

I want to get them in the same order to update a property which depends on
the sequence in which items were added in the collection.

Regards,
Sugandh
 
Hello Sugandh,

Do u need smth like HashList?! http://www.codeproject.com/csharp/hashlistarticle.asp

---
WBR, Michael Nemtsev [.NET/C# MVP].
My blog: http://spaces.live.com/laflour
Team blog: http://devkids.blogspot.com/

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo

SJ> confusion is as follows:
SJ>
SJ> If I have a collection of a particular type of object.
SJ>
SJ> While moving in the collection using foreach or forloop, will I get
SJ> the taxlots in the same order in which they were inserted into the
SJ> collection.
SJ>
 
Hi,

I am developing using MS Visual Studio .net 2005, c# 2.0.

My query/confusion is as follows:

If I have a collection of a particular type of object.

While moving in the collection using foreach or forloop, will I get the
taxlots in the same order in which they were inserted into the collection.

I want to get them in the same order to update a property which depends on
the sequence in which items were added in the collection.

Regards,
Sugandh

Dear Sugandh,

It depends on the type of the collection you choose.

Arrays typically maintain insertion order while Hash tables don't.

I would suggest to use the generic List which maintains the index of
the items.

Hope this helps,
Moty
 
I did check whether its maintained or not.
it is actually maintained and i have written the code required.
it is actually a list specific to the Type.

Regards,
Sugandh
 
Hi,

Sugandh Jain said:
I did check whether its maintained or not.
it is actually maintained and i have written the code required.

Unless it's especified in the docs do not assume that. It might change later
on.
 
Back
Top