Item property and indexer

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dotnetjunky

    Item property and indexer

    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.Cach ing.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.Cac hing.Cache' does not contain a definition for 'Item'

    Can someone explain this strange behavior to me ?

    Thanks a lot.

    --
    Dotnetjunky



  • Rob Windsor

    #2
    Re: Item property and indexer

    Check this link out, it explains indexers in detail.



    --
    Rob Windsor
    G6 Consulting
    Toronto, Canada


    "Dotnetjunk y" <dotnetjunky@no reply.com> wrote in message
    news:%23q938cFe DHA.1736@TK2MSF TNGP12.phx.gbl. ..[color=blue]
    > 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.Cach ing.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"],[/color]
    the[color=blue]
    > compiler complains:
    >
    > 'System.Web.Cac hing.Cache' does not contain a definition for 'Item'
    >
    > Can someone explain this strange behavior to me ?
    >
    > Thanks a lot.
    >
    > --
    > Dotnetjunky
    >
    >
    >[/color]


    Comment

    • Ignacio Machin

      #3
      Re: Item property and indexer

      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

      "Dotnetjunk y" <dotnetjunky@no reply.com> wrote in message
      news:%23q938cFe DHA.1736@TK2MSF TNGP12.phx.gbl. ..[color=blue]
      > 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.Cach ing.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"],[/color]
      the[color=blue]
      > compiler complains:
      >
      > 'System.Web.Cac hing.Cache' does not contain a definition for 'Item'
      >
      > Can someone explain this strange behavior to me ?
      >
      > Thanks a lot.
      >
      > --
      > Dotnetjunky
      >
      >
      >[/color]


      Comment

      • Dotnetjunky

        #4
        Re: Item property and indexer

        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" <ignacio.mach in AT dot.state.fl.us > wrote in message
        news:O27bsEGeDH A.2228@TK2MSFTN GP12.phx.gbl...[color=blue]
        > 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
        >
        > "Dotnetjunk y" <dotnetjunky@no reply.com> wrote in message
        > news:%23q938cFe DHA.1736@TK2MSF TNGP12.phx.gbl. ..[color=green]
        > > 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.Cach ing.Cache for example. In the[/color][/color]
        documentation,[color=blue][color=green]
        > > there's a property called Item and the description is:
        > >
        > > "Gets or sets the cache item at the specified key. In C#, this property[/color][/color]
        is[color=blue][color=green]
        > > the indexer for the Cache class."
        > >
        > > But when I tried to access this property, using Cache.Item["keyVaule"],[/color]
        > the[color=green]
        > > compiler complains:
        > >
        > > 'System.Web.Cac hing.Cache' does not contain a definition for 'Item'
        > >
        > > Can someone explain this strange behavior to me ?
        > >
        > > Thanks a lot.
        > >
        > > --
        > > Dotnetjunky
        > >
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • Mattias Sjögren

          #5
          Re: Item property and indexer

          [color=blue]
          >Is it correct that the Item property is only for other languages, but not C#?[/color]

          Yes



          Mattias

          --
          Mattias Sjögren [MVP] mattias @ mvps.org

          Please reply only to the newsgroup.

          Comment

          Working...