Item property of Collection classes not support by CF

  • Thread starter Thread starter Henrik Bach
  • Start date Start date
H

Henrik Bach

So, the Compact Framework version of all the Collection classes does not
support the property Item. So how the hell can I get the value object from a
hashtable with a given key? I can ask if the key is in the hashtable (by
using the Contains method), but without the Item property I don't know how
to get the value object associated with the key. Can somebody help? Ok, I
can iterate through the whole hashtable to find what I want, but then I
might as well implement my own collection from scratch.

Thanks,
Henrik Bach
 
Not sure what is the problem with Hasthable.
Class Hashtable has a method Item(key as Object) (or for C# an indexer
this[object key]).
The ICollection interface does not allow direct item addressing - for that
you need IList

PS "How the hell" and "Thanks" belong to two different writing styles :)
 
Hi,

I hit the same problem as Henrik, although the Normal .NET Framework
has an Item() method (and c# indexer etc.), it seems that the Compact
..NET framework does not (documented in the MSDN). Nor it seems does
ArrayList! It is hard to see the point of Hashtable if you can add
Key/Object pairs but can't then query for Object by Key, hmmmm.. all
very strange...

Any insight appreciated

KevinG.

Alex Feinman said:
Not sure what is the problem with Hasthable.
Class Hashtable has a method Item(key as Object) (or for C# an indexer
this[object key]).
The ICollection interface does not allow direct item addressing - for that
you need IList

PS "How the hell" and "Thanks" belong to two different writing styles :)

Henrik Bach said:
So, the Compact Framework version of all the Collection classes does not
support the property Item. So how the hell can I get the value object from a
hashtable with a given key? I can ask if the key is in the hashtable (by
using the Contains method), but without the Item property I don't know how
to get the value object associated with the key. Can somebody help? Ok, I
can iterate through the whole hashtable to find what I want, but then I
might as well implement my own collection from scratch.

Thanks,
Henrik Bach
 
Actually the point of my reply is that *there is* Item property in the
hashtable. You can write:

Hashtable h = new Hashtable();
h.Add("English", "John");
h.Add("French", "Jean");
h.Add("Italian", "Giovanny");
h.["Spanish"] = "Juan";
MessageBox.Show(h["English"].ToString())

KevinG said:
Hi,

I hit the same problem as Henrik, although the Normal .NET Framework
has an Item() method (and c# indexer etc.), it seems that the Compact
.NET framework does not (documented in the MSDN). Nor it seems does
ArrayList! It is hard to see the point of Hashtable if you can add
Key/Object pairs but can't then query for Object by Key, hmmmm.. all
very strange...

Any insight appreciated

KevinG.

"Alex Feinman [MVP]" <[email protected]> wrote in message
Not sure what is the problem with Hasthable.
Class Hashtable has a method Item(key as Object) (or for C# an indexer
this[object key]).
The ICollection interface does not allow direct item addressing - for that
you need IList

PS "How the hell" and "Thanks" belong to two different writing styles :)

Henrik Bach said:
So, the Compact Framework version of all the Collection classes does not
support the property Item. So how the hell can I get the value object
from
a
hashtable with a given key? I can ask if the key is in the hashtable (by
using the Contains method), but without the Item property I don't know how
to get the value object associated with the key. Can somebody help? Ok, I
can iterate through the whole hashtable to find what I want, but then I
might as well implement my own collection from scratch.

Thanks,
Henrik Bach
 
Back
Top