473,378 Members | 1,441 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Dictionary collection

Is there anything that combines the features of a dictionary and a collection
such that items can be retrieved by either their key or their index? I think
this is how vb.6 collections worked?
Jul 22 '05 #1
6 1562
I haven't tried this, but I think that for any of the dictionary-type
collections (Hashtable, HybridDictionary, ListDictionary, et al.) you
could access the values by index by using the Values property, which
should be indexable.

Hastable foo = new Hastable();

// Populate hashtable
..
..
..

// Index through items
for (int index = 0; index < foo.Count; ++index) {
object bar = foo.Values[index];
Jul 22 '05 #2
Forget it. Doesn't work.

Jul 22 '05 #3
Sorry but MyBase.Dictionary.Values returns an ICollection which, as far as I
can, isn't indexable. As you say, you didn't try it, so appologies accepted :)

"Adam" wrote:
I haven't tried this, but I think that for any of the dictionary-type
collections (Hashtable, HybridDictionary, ListDictionary, et al.) you
could access the values by index by using the Values property, which
should be indexable.

Hastable foo = new Hastable();

// Populate hashtable
..
..
..

// Index through items
for (int index = 0; index < foo.Count; ++index) {
object bar = foo.Values[index];
.
.
.
}

Like I said, this is off the top of my head and I haven't tried it. I
apologize in advance if I have misled you.

Regards,

Adam

Jul 22 '05 #4
Dick,

You can reference Microsoft.VisualBasic.dll and use the Collection
class.

Brian

Dick wrote:
Is there anything that combines the features of a dictionary and a collection
such that items can be retrieved by either their key or their index? I think
this is how vb.6 collections worked?


Jul 22 '05 #5

Hi there,

Please see System.Collections.Specialized.NameValueCollection

The Specialized namespace contains collections that do what you are looking
for.

Good luck!

--
Juan Romero
-----------------------------------------
The successful person has the habit of doing the things failures don't like
to do.
E.M. Gray
"Dick" wrote:
Is there anything that combines the features of a dictionary and a collection
such that items can be retrieved by either their key or their index? I think
this is how vb.6 collections worked?

Jul 22 '05 #6
Madestro <me_no_like_spam_juanDOTromero@bowneDOTcom> wrote:
Please see System.Collections.Specialized.NameValueCollection

The Specialized namespace contains collections that do what you are looking
for.


It's not quite the same:

1) It only deals with strings
2) It adds multiple values for the same key, comma-separating them

I don't see anything in System.Collections.Specialized which solves the
OP's problem, unless he happens to be looking for strings.

Personally I'd write a class which aggregates a list and a dictionary,
and provide the appropriate access methods. (Care is needed in terms of
what it means to replace the entry at a particular index, etc - it may
be simpler to make it an "add only" type of collection.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 22 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: boohoo | last post by:
I can't seem to do this: I want to take a query string and place two halves of the querystring into two separate dictionary objects. So... I loop through the collection of querystring items,...
9
by: What-a-Tool | last post by:
Dim MyMsg Set MyMsg = server.createObject("Scripting.Dictionary") MyMsg.Add "KeyVal1", "My Message1" MyMsg.Add "KeyVal2", "My Message2" MyMsg.Add "KeyVal3", "My Message3" for i = 1 To...
4
by: Martin Widmer | last post by:
Hi folks. I am using this collection class: Public Class ContentBlocksCollection Inherits DictionaryBase 'Object variables for attributes 'Attributes Default Public Property Item(ByVal...
1
by: Martin Widmer | last post by:
Hi Folks. When I iterate through my custom designed collection, I always get the error: "Unable to cast object of type 'System.Collections.DictionaryEntry' to type...
7
by: bonk | last post by:
Hello I am acessing a Dictionary<TKey,TValuefrom multiple threads and often in a foreach loop. While I am within one of the foreach loops the other threads must not modify the collection itself...
7
by: Andrew Robinson | last post by:
I have a method that needs to return either a Dictionary<k,vor a List<v> depending on input parameters and options to the method. 1. Is there any way to convert from a dictionary to a list...
2
by: Stephen Costanzo | last post by:
I have: Public Class test Private displayValue As String Private dbType As Integer Property Display() As String Get Return displayValue End Get
8
by: Andy B | last post by:
I have the object property StockContract.Dictionary which is a dictionary collection of <string, stringkey/value pairs. I need to be able to retreive the keys and their values and display them on a...
2
by: Andy B | last post by:
I don't know if this is even working or not but here is the problem. I have a gridview that I databound to a dictionary<string, stringcollection: Contract StockContract = new Contract();...
2
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
I'm pulling records from or database by dates, and there are multiple records for each part number. The part numbers are being stored as strings in a List in a custom Employee class: ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.