hashtable

  • Thread starter Thread starter Ilann
  • Start date Start date
I

Ilann

Hi,

I'm trying to create a new Hashtable and use it:

System.Collections.Hashtable hash_directory;

hash_directory.Item("blabla");

and here is the error message I get:

'System.Collections.Hashtable' does not contain a definition for 'Item'

any idea??

Thanks

Ilann
 
See the online help under "HashTable.Item" and there is a note that says:
"In C#, this property is the indexer for the Hashtable class."

so use the indexer version:
hash_directory["blabla"]

ShaneB
 
Hi,

I'm trying to create a new Hashtable and use it:

System.Collections.Hashtable hash_directory;

hash_directory.Item("blabla");

and here is the error message I get:

'System.Collections.Hashtable' does not contain a definition for
'Item'

any idea??

Thanks

Ilann

Ilann,

You must first create an instance of the hashtable before it can be
used:

Hashtable hash_directory = new Hashtable();

Please see the help file entry for System.Collections.Hashtable for
some example code.
 
and Hashtable is a class that implements IDictionary interface, so there
should a Key/Value pair in Hashtable.
for example: hash["blahKey"] = "blahValue";

Maqsood Ahmed
Kolachi Advanced Technologies
http://www.kolachi.net
 
You must first create an instance of the hashtable before it can be
used:

Hashtable hash_directory = new Hashtable();

While that's true, it's not the reason for the error message. The error
message is because C# doesn't use named properties like that; it uses
the "default" property for a class as an indexer:

object o = hash_directory["blabla"];
 
You must first create an instance of the hashtable before it
can be used:

Hashtable hash_directory = new Hashtable();

While that's true, it's not the reason for the error message.
The error message is because C# doesn't use named properties
like that; it uses the "default" property for a class as an
indexer:

object o = hash_directory["blabla"];

Jon,

Yeah, I know. Rather than re-type what's already readily available
in the help file, I decided to just direct him there.

Chris.
 
Back
Top