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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Indexer vs function

Indexer vs function

Scheduled Pinned Locked Moved C#
questionvisual-studio
2 Posts 2 Posters 1 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.
  • A Offline
    A Offline
    axos88
    wrote on last edited by
    #1

    What is the difference, and why is one better then the other? I mean indexer vs public foo Items(string name) { some code here; return respective item; } Thanks, Vandra Akos

    L 1 Reply Last reply
    0
    • A axos88

      What is the difference, and why is one better then the other? I mean indexer vs public foo Items(string name) { some code here; return respective item; } Thanks, Vandra Akos

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      on the righthand side of a statement, a function can perfectly replace an indexer. On the lefthand side it can't.

      // You can write:

      var = object[index]; // or var=object.someMethod(index);

      // but also:

      object[index] = value;
      object[index]++;

      Of course, one can live without indexers (as C and Java have proven) but they make it possible to improve code readability. :) -- modified at 17:07 Thursday 28th December, 2006

      Luc Pattyn

      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