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. Indexers [modified]

Indexers [modified]

Scheduled Pinned Locked Moved C#
questionc++discussion
12 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.
  • C Offline
    C Offline
    c2423
    wrote on last edited by
    #1

    I just discovered indexers today (using Reflector and a bit of googling) and found that they solve some problems I had been having with a class. Having just found them, my initial thoughts were "excellent! this solves all of the problems of the world" So my question is this: Are indexers common knowledge (and I have been living under a rock until today) OR Are indexers obscure things only usually found in the System.whatever? (The reason I ask is that the project I'm working on seems like a candidate for an article, but when I write it I dont want to patronise people by telling them all about this magic syntax I discovered if everybody already knows) Thanks, Chris [Edit: After a couple of replies it seems that it is common knowledge, however I suspect that people have come from a C++ background - any VB background people care to chip in?]

    modified on Monday, August 18, 2008 11:17 AM

    L L 2 Replies Last reply
    0
    • C c2423

      I just discovered indexers today (using Reflector and a bit of googling) and found that they solve some problems I had been having with a class. Having just found them, my initial thoughts were "excellent! this solves all of the problems of the world" So my question is this: Are indexers common knowledge (and I have been living under a rock until today) OR Are indexers obscure things only usually found in the System.whatever? (The reason I ask is that the project I'm working on seems like a candidate for an article, but when I write it I dont want to patronise people by telling them all about this magic syntax I discovered if everybody already knows) Thanks, Chris [Edit: After a couple of replies it seems that it is common knowledge, however I suspect that people have come from a C++ background - any VB background people care to chip in?]

      modified on Monday, August 18, 2008 11:17 AM

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      c2423 wrote:

      Are indexers common knowledge

      Yes

      c2423 wrote:

      (and I have been living under a rock until today)

      I don't know. :)

      led mike

      C 1 Reply Last reply
      0
      • L led mike

        c2423 wrote:

        Are indexers common knowledge

        Yes

        c2423 wrote:

        (and I have been living under a rock until today)

        I don't know. :)

        led mike

        C Offline
        C Offline
        c2423
        wrote on last edited by
        #3

        Thanks for your input! In conclusion I must just not have been paying attention to the C# books I glossed over... Chris

        L 1 Reply Last reply
        0
        • C c2423

          I just discovered indexers today (using Reflector and a bit of googling) and found that they solve some problems I had been having with a class. Having just found them, my initial thoughts were "excellent! this solves all of the problems of the world" So my question is this: Are indexers common knowledge (and I have been living under a rock until today) OR Are indexers obscure things only usually found in the System.whatever? (The reason I ask is that the project I'm working on seems like a candidate for an article, but when I write it I dont want to patronise people by telling them all about this magic syntax I discovered if everybody already knows) Thanks, Chris [Edit: After a couple of replies it seems that it is common knowledge, however I suspect that people have come from a C++ background - any VB background people care to chip in?]

          modified on Monday, August 18, 2008 11:17 AM

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Indexers are nice and commonly used in the .NET framework. If you think they would make sense in your project and simplify the usage of it, then go for indexers. regards

          C 1 Reply Last reply
          0
          • L Lost User

            Indexers are nice and commonly used in the .NET framework. If you think they would make sense in your project and simplify the usage of it, then go for indexers. regards

            C Offline
            C Offline
            c2423
            wrote on last edited by
            #5

            Yes, they simplify my project (in one place I even save an *entire line* of code :laugh: ) And I know that the framework contains them (for example when reading a SqlDataReader's values) However, my question was more along the lines of "do people generally know of their existance?" Anyway, thanks for your input - its good to know that its not an alien concept for people! Thanks, Chris

            L 1 Reply Last reply
            0
            • C c2423

              Yes, they simplify my project (in one place I even save an *entire line* of code :laugh: ) And I know that the framework contains them (for example when reading a SqlDataReader's values) However, my question was more along the lines of "do people generally know of their existance?" Anyway, thanks for your input - its good to know that its not an alien concept for people! Thanks, Chris

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              c2423 wrote:

              However, my question was more along the lines of "do people generally know of their existance?"

              I think most people use them intuitively when accessing chars in strings, items in lists, values by key in dictionaries and lots of other stuff. Whenever the user knows that there's more data inside a class they either look for a GetXXX-Method or go for indexers without actually knowing that they just use "indexers". regards

              C 1 Reply Last reply
              0
              • L Lost User

                c2423 wrote:

                However, my question was more along the lines of "do people generally know of their existance?"

                I think most people use them intuitively when accessing chars in strings, items in lists, values by key in dictionaries and lots of other stuff. Whenever the user knows that there's more data inside a class they either look for a GetXXX-Method or go for indexers without actually knowing that they just use "indexers". regards

                C Offline
                C Offline
                c2423
                wrote on last edited by
                #7

                Perhaps I wasn't being clear in my posts:

                Greeeg wrote:

                I think most people use them intuitively

                Which is why I want to use them for my class :) However there is a difference between understanding:

                string x = "hello world";
                char y = x[0];

                And being able to write:

                this[int indexno]
                {
                get { return something; }
                }

                What I wanted to know was are people familiar with how to add this functionality to a class, rather then can people use a class which already has this functionality.

                L 1 Reply Last reply
                0
                • C c2423

                  Perhaps I wasn't being clear in my posts:

                  Greeeg wrote:

                  I think most people use them intuitively

                  Which is why I want to use them for my class :) However there is a difference between understanding:

                  string x = "hello world";
                  char y = x[0];

                  And being able to write:

                  this[int indexno]
                  {
                  get { return something; }
                  }

                  What I wanted to know was are people familiar with how to add this functionality to a class, rather then can people use a class which already has this functionality.

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  c2423 wrote:

                  What I wanted to know was are people familiar with how to add this functionality to a class, rather then can people use a class which already has this functionality.

                  This totally depends on the experience of the developer :confused: Experienced developers who have been programming with C# for quite a while will definitely know of their existence, while newcomers to C# probably miss them and go the GetXXX-way.

                  D C 2 Replies Last reply
                  0
                  • C c2423

                    Thanks for your input! In conclusion I must just not have been paying attention to the C# books I glossed over... Chris

                    L Offline
                    L Offline
                    led mike
                    wrote on last edited by
                    #9

                    c2423 wrote:

                    Thanks for your input!

                    No problem. Man I sure missed an opportunity in replying to your other question!

                    c2423 wrote:

                    (and I have been living under a rock until today)

                    I don't know, what's your address? I can look it up on Google Street View and tell you! :-D

                    led mike

                    1 Reply Last reply
                    0
                    • L Lost User

                      c2423 wrote:

                      What I wanted to know was are people familiar with how to add this functionality to a class, rather then can people use a class which already has this functionality.

                      This totally depends on the experience of the developer :confused: Experienced developers who have been programming with C# for quite a while will definitely know of their existence, while newcomers to C# probably miss them and go the GetXXX-way.

                      D Offline
                      D Offline
                      Dr Emmett Brown
                      wrote on last edited by
                      #10

                      When I first read "Indexer" I didn't know what you mean, but after seeing the example I realized you were talking about the [] operator. I think that almost every C++ developer might know that, as you can overload a lot of operators in C++ and it's something very useful. BTW, the GetXXX method, is a method that connects to the internet and downloads adult contents from a porn site. :laugh:

                      rotter

                      C 1 Reply Last reply
                      0
                      • L Lost User

                        c2423 wrote:

                        What I wanted to know was are people familiar with how to add this functionality to a class, rather then can people use a class which already has this functionality.

                        This totally depends on the experience of the developer :confused: Experienced developers who have been programming with C# for quite a while will definitely know of their existence, while newcomers to C# probably miss them and go the GetXXX-way.

                        C Offline
                        C Offline
                        c2423
                        wrote on last edited by
                        #11

                        Again, not quite what I was looking for, but I think my question has been answered now anyway. Thanks, Chris

                        1 Reply Last reply
                        0
                        • D Dr Emmett Brown

                          When I first read "Indexer" I didn't know what you mean, but after seeing the example I realized you were talking about the [] operator. I think that almost every C++ developer might know that, as you can overload a lot of operators in C++ and it's something very useful. BTW, the GetXXX method, is a method that connects to the internet and downloads adult contents from a porn site. :laugh:

                          rotter

                          C Offline
                          C Offline
                          c2423
                          wrote on last edited by
                          #12

                          Thanks, exactly the answer I was looking for.

                          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