Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. Indexers

Indexers

Scheduled Pinned Locked Moved Managed C++/CLI
csharpc++
5 Posts 2 Posters 16 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Michael Mac
    wrote on last edited by
    #1

    I'm writting an app in MC++. One of its class is a collection and I don't know what to do to have indexers in C#. When I disassemble C# code the indexer function is as follow:

    get_Item : class System.String(int32)

    I tried to add function like this but I didn't work. :(( Can somebody tell if it's possible.

    J 1 Reply Last reply
    0
    • M Michael Mac

      I'm writting an app in MC++. One of its class is a collection and I don't know what to do to have indexers in C#. When I disassemble C# code the indexer function is as follow:

      get_Item : class System.String(int32)

      I tried to add function like this but I didn't work. :(( Can somebody tell if it's possible.

      J Offline
      J Offline
      James T Johnson
      wrote on last edited by
      #2

      Create a property called Item which takes a common parameter in both its set/get functions. ie

      __property System::String* get_Item(int index)
      {
      ....
      }

      __property void set_Item(int index, System::String* value)
      {
      ....
      }

      I don't see anything that lets you create a C# indexer were the class instance can be treated as an array; I assume if you use the Item property name it allows C# to use it as if it were one. HTH, James

      M 1 Reply Last reply
      0
      • J James T Johnson

        Create a property called Item which takes a common parameter in both its set/get functions. ie

        __property System::String* get_Item(int index)
        {
        ....
        }

        __property void set_Item(int index, System::String* value)
        {
        ....
        }

        I don't see anything that lets you create a C# indexer were the class instance can be treated as an array; I assume if you use the Item property name it allows C# to use it as if it were one. HTH, James

        M Offline
        M Offline
        Michael Mac
        wrote on last edited by
        #3

        I don't work. C++ function disassembly is

        .method public specialname instance string
        get_Item(int32 index) cil managed

        and C# is

        .method public hidebysig specialname instance string
        get_Item(int32 index) cil managed

        Mayby it's possible to write this function in CLR?

        J 1 Reply Last reply
        0
        • M Michael Mac

          I don't work. C++ function disassembly is

          .method public specialname instance string
          get_Item(int32 index) cil managed

          and C# is

          .method public hidebysig specialname instance string
          get_Item(int32 index) cil managed

          Mayby it's possible to write this function in CLR?

          J Offline
          J Offline
          James T Johnson
          wrote on last edited by
          #4

          It appears Indexers created in MC++ only work in MC++ AND you can't create an indexer that operates on a class instance. I'll look into it more after the hockey game :) James

          M 1 Reply Last reply
          0
          • J James T Johnson

            It appears Indexers created in MC++ only work in MC++ AND you can't create an indexer that operates on a class instance. I'll look into it more after the hockey game :) James

            M Offline
            M Offline
            Michael Mac
            wrote on last edited by
            #5

            I'll appreciate it. :) Thanks

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups