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. C#
  4. C# operator overloading

C# operator overloading

Scheduled Pinned Locked Moved C#
questioncsharp
4 Posts 4 Posters 0 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.
  • T Offline
    T Offline
    ting668
    wrote on last edited by
    #1

    What is the syntax of overloading "[]" for a arraylist extended class? Thanks

    S J T 3 Replies Last reply
    0
    • T ting668

      What is the syntax of overloading "[]" for a arraylist extended class? Thanks

      S Offline
      S Offline
      Stefan Troschuetz
      wrote on last edited by
      #2

      In C#, the indexer for the ArrayList class is the Item property, so you'll have to overload this.


      www.troschuetz.de

      1 Reply Last reply
      0
      • T ting668

        What is the syntax of overloading "[]" for a arraylist extended class? Thanks

        J Offline
        J Offline
        J4amieC
        wrote on last edited by
        #3

        you can use the new keyword if a method/accessor is not marked virtual. eg public class MyArrayList : ArrayList { public new object this[int i] { get{ return base[i]; } set{ base[i] = value; } }

        1 Reply Last reply
        0
        • T ting668

          What is the syntax of overloading "[]" for a arraylist extended class? Thanks

          T Offline
          T Offline
          turbochimp
          wrote on last edited by
          #4

          What you're looking for is not an operator ("[]"). It's called an indexer (as previously mentioned), and while ArrayList does expose an Item property, the property you'll need to overload (or override) is the this property : e.g. public object this[Guid objectKey] { get{...} set{...} } public object this[string objectName] { get{...} set{...} } I'm not sure what your plan for this is, but you may also want to consider implementing the ICollection interface (probably the CollectionBase class) if you're working on making a strongly typed collection. It uses an ArrayList internally. Hope this helps.

          The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’

          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