Item property and indexer

  • Thread starter Thread starter Dotnetjunky
  • Start date Start date
D

Dotnetjunky

Hi,

I'm really get confused on this issue. Hope that someone can help me get
clear after this post.

Take the class System.Web.Caching.Cache for example. In the documentation,
there's a property called Item and the description is:

"Gets or sets the cache item at the specified key. In C#, this property is
the indexer for the Cache class."

But when I tried to access this property, using Cache.Item["keyVaule"], the
compiler complains:

'System.Web.Caching.Cache' does not contain a definition for 'Item'

Can someone explain this strange behavior to me ?

Thanks a lot.
 
Hi,

In these cases where the doc say that the property X is the indexer you
access it without the property name, the compiler knows how to find it,
cause it's the indexer.

you access it using Cache["key"] you do not have to use the .Item
construction.

Hope this help,
 
So, my question is why the doc shows the Item property ?
Is it correct that the Item property is only for other languages, but not C#
?

--
Dotnetjunky


Ignacio Machin said:
Hi,

In these cases where the doc say that the property X is the indexer you
access it without the property name, the compiler knows how to find it,
cause it's the indexer.

you access it using Cache["key"] you do not have to use the .Item
construction.

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Dotnetjunky said:
Hi,

I'm really get confused on this issue. Hope that someone can help me get
clear after this post.

Take the class System.Web.Caching.Cache for example. In the documentation,
there's a property called Item and the description is:

"Gets or sets the cache item at the specified key. In C#, this property is
the indexer for the Cache class."

But when I tried to access this property, using Cache.Item["keyVaule"], the
compiler complains:

'System.Web.Caching.Cache' does not contain a definition for 'Item'

Can someone explain this strange behavior to me ?

Thanks a lot.
 
Back
Top