473,221 Members | 1,940 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,221 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 1555
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: ...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.