473,396 Members | 1,726 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,396 software developers and data experts.

hashtable

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
Nov 16 '05 #1
5 4404
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

"Ilann" <il***@free.fr> wrote in message
news:ef**************@tk2msftngp13.phx.gbl...
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

Nov 16 '05 #2
"Ilann" <il***@free.fr> wrote in
news:ef**************@tk2msftngp13.phx.gbl:
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.

--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 16 '05 #3
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #4
Chris R. Timmons <crtimmons@X_NOSPAM_Xcrtimmonsinc.com> wrote:
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??
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 Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #5
Jon Skeet [C# MVP] <sk***@pobox.com> wrote in
news:MP************************@msnews.microsoft.c om:
Chris R. Timmons <crtimmons@X_NOSPAM_Xcrtimmonsinc.com> wrote:
> 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??

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.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 16 '05 #6

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

Similar topics

5
by: francois | last post by:
First of all I would to to apologize for resending this post again but I feel like my last post as been spoiled Here I go for my problem: Hi, I have a webservice that I am using and I would...
5
by: Cyrus | last post by:
I have a question regarding synchronization across multiple threads for a Hashtable. Currently I have a Threadpool that is creating worker threads based on requests to read/write to a hashtable....
8
by: SenthilVel | last post by:
how to get the corresponding values for a given Key in hashtable ??
33
by: Ken | last post by:
I have a C# Program where multiple threads will operate on a same Hashtable. This Hashtable is synchronized by using Hashtable.Synchronized(myHashtable) method, so no further Lock statements are...
16
by: Sreekanth | last post by:
Hello, Is there any better collection than HashTable in terms of performance, when the type of the key is integer? Regards, Sreekanth.
3
by: Fred | last post by:
I'm trying to build a hashtable and a arraylist as object value I'm not able to retrieve stored object from the hashtable. Hashtable mp = new Hashtable(); // THE HASHTABLE ArrayList...
8
by: Robin Tucker | last post by:
When I create a hashtable hashing on Object-->Item, can I mix "string" and "integer" as the key types? I have a single thumbnail cache for a database with (hashed on key) and a file view (hashed...
7
by: SevDer | last post by:
Hi We have a static hashtable that is located in another tier in our n-tiered web application. And we are storing big but not huge objects in this hashtable and the key to the objects is...
2
by: PAzevedo | last post by:
I have this Hashtable of Hashtables, and I'm accessing this object from multiple threads, now the Hashtable object is thread safe for reading, but not for writing, so I lock the object every time I...
2
by: archana | last post by:
Hi all, I am having one confusion regarding hashtable. I am having function in which i am passing hashtable as reference. In function i am creating one hashtable which is local to that...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.