Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / October 2007

Tip: Looking for answers? Try searching our database.

ListDictionary/NameValueCollection question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Vikas Manghani - 25 Oct 2007 16:25 GMT
Hi
I have a situation wherein I need  hashtable type functionality and at the
same time, the collection must preserve the order of the items.
In other words, if I add items

Key     Value
"a"       "Val - A"
"X"       "Val - X"
"b"        "Val - B"
When I enumerate over the collection, I should get items in the same order
as inserted. I read at some site that ListDictionary and NameValueCollection
support this. But I am not sure about the same. Can anyone confirm if I can
use any of these collections?

Thanks and regards
Vikas Manghani
Jon Skeet [C# MVP] - 25 Oct 2007 16:51 GMT
On Oct 25, 4:25 pm, Vikas Manghani
<VikasMangh...@discussions.microsoft.com> wrote:
> I have a situation wherein I need  hashtable type functionality and at the
> same time, the collection must preserve the order of the items.
[quoted text clipped - 8 lines]
> support this. But I am not sure about the same. Can anyone confirm if I can
> use any of these collections?

I don't believe either of those preserve insertion order. The easiest
way is to maintain both a List<T> and a Dictionary<K,V>. I'm sure
there are classes available on the net which do this for you, of
course, but in many cases it's easy just to keep both (the list being
a list of keys) and update it yourself.

Jon

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.