Order of Items in a collection object

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
 
M

Michael Nemtsev

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>
 
M

Moty Michaely

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
 
S

Sugandh Jain

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
 
I

Ignacio Machin \( .NET/ C# MVP \)

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top