
Signature
omnibus ex nihilo ducendis sufficit unum
Spaces inserted to prevent google email destruction:
MSN oliver @ sturmnet.org Jabber sturm @ amessage.de
ICQ 27142619 http://www.sturmnet.org/blog
ok - this is not what the docs or associated examples clearly state, but i
will take your word for it and assume that the docs are just baked.
this does/can cause a problem though.
if you add a number of items as :
ld.Add("Item1","value1");
ld.Add("Item2","value2");
ld.Add("Item3","value3");
then you can access them as :
ld["Item1"];
ld["Item2"];
ld["Item3"];
but there is no way to access them as :
ld[0];
ld[1];
ld[2];
ie. i want the say the 1st or last item and I have no idea what any of the
contained item ids are.
these all return null which imo they should
this is what the docs state that the Item property was supposed to be for.
I suppose i could do :
foreach( DictionaryEntry de in ld ) {
val=de.Value;
exit;
}
or
((DictionaryEntry)ld.GetEnumerator().Current).Value;
but that seems rather ridiculous to me - mucho overhead.
there is also ld.Keys & ld.Values but I haven't figure out to actually get
anything out of these 2 properties other than to CopyTo an Array.
> > Are the docs completely baked on this or am I missing something basic here ?
>
[quoted text clipped - 8 lines]
>
> Oliver Sturm
Jon Skeet [C# MVP] - 02 Aug 2005 22:42 GMT
> ok - this is not what the docs or associated examples clearly state, but i
> will take your word for it and assume that the docs are just baked.
No, the docs state:
<quote>
In C#, this property is the indexer for the ListDictionary class.
</quote>
I can't see anything in the examples which suggests anything else.
> this does/can cause a problem though.
>
[quoted text clipped - 7 lines]
> ld["Item2"];
> ld["Item3"];
Indeed.
> but there is no way to access them as :
> ld[0];
> ld[1];
> ld[2];
> ie. i want the say the 1st or last item and I have no idea what any of the
> contained item ids are.
Then you should maintain a parallel IList implementation. A
ListDictionary is an IDictionary which happens to be implemented using
a list internally - it isn't a list in itself.
> these all return null which imo they should
Absolutely.
> this is what the docs state that the Item property was supposed to be for.
No it's not. The Item property
> I suppose i could do :
> foreach( DictionaryEntry de in ld ) {
[quoted text clipped - 4 lines]
> ((DictionaryEntry)ld.GetEnumerator().Current).Value;
> but that seems rather ridiculous to me - mucho overhead.
More importantly, there's no guarantee that that will come out in the
order you expect.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Oliver Sturm - 03 Aug 2005 09:49 GMT
> if you add a number of items as :
> ld.Add("Item1","value1");
[quoted text clipped - 5 lines]
> ld["Item2"];
> ld["Item3"];
If the class in question has an indexer that takes a string argument
instead of the int that I used in my sample, you'll have to pass in a
string to get to the items. This is true, for example, for the Hashtable
or Dictionary<T> and similar classes.
> but there is no way to access them as :
> ld[0];
> ld[1];
> ld[2];
If you want to access the items by a string key AND an int key, you'll
have to have multiple indexers that take different types of parameters.
How you implement that is not the business of the .NET docs :-) As John
suggests, you'll probably want to add an additional collection structure
to your storage class, to be able to access the items efficiently from
both indexers.
Oliver Sturm

Signature
omnibus ex nihilo ducendis sufficit unum
Spaces inserted to prevent google email destruction:
MSN oliver @ sturmnet.org Jabber sturm @ amessage.de
ICQ 27142619 http://www.sturmnet.org/blog