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. Indexer question

Indexer question

Scheduled Pinned Locked Moved C#
helpquestiondatabasetutorial
5 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.
  • A Offline
    A Offline
    Andrei Ungureanu
    wrote on last edited by
    #1

    Hi, I have a small problem. I want to create 2 properties to one of my classes. All I want is to make easier for the users of my class to get some data out of my class. I want when a user writes

    Test[i]

    to get some data and when the user writes

    Test[i][j]

    to get another type of response. I need a little help with the second type of property:

    public class Test
    {
    //some data

    public object this[int index]
    {
    get
    {
    //get data
    }
    }
    }

    This one works. My question is how to write the second one? Thanks in advance

    Do your best to be the best

    C E I 3 Replies Last reply
    0
    • A Andrei Ungureanu

      Hi, I have a small problem. I want to create 2 properties to one of my classes. All I want is to make easier for the users of my class to get some data out of my class. I want when a user writes

      Test[i]

      to get some data and when the user writes

      Test[i][j]

      to get another type of response. I need a little help with the second type of property:

      public class Test
      {
      //some data

      public object this[int index]
      {
      get
      {
      //get data
      }
      }
      }

      This one works. My question is how to write the second one? Thanks in advance

      Do your best to be the best

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      The second is a result of the first. Test[i][j] can be broken down like this:

      B someB = someA[i];
      object result = someB[j];

      or it can be written in a compressed form like this:

      object result = someA[i][j];

      The classes look like this:

      public A
      {
      public B this[int index]
      {
      get
      {
      return stuff
      }
      }
      }

      public B
      {
      public object this[int index]
      {
      get
      {
      return stuff
      }
      }

      }

      Does this help?


      Upcoming Scottish Developers events: * UK Security Evangelists On Tour (2nd November, Edinburgh) * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

      A 1 Reply Last reply
      0
      • A Andrei Ungureanu

        Hi, I have a small problem. I want to create 2 properties to one of my classes. All I want is to make easier for the users of my class to get some data out of my class. I want when a user writes

        Test[i]

        to get some data and when the user writes

        Test[i][j]

        to get another type of response. I need a little help with the second type of property:

        public class Test
        {
        //some data

        public object this[int index]
        {
        get
        {
        //get data
        }
        }
        }

        This one works. My question is how to write the second one? Thanks in advance

        Do your best to be the best

        E Offline
        E Offline
        e laj
        wrote on last edited by
        #3

        If the returning type from your indexer has indexer, it will work. Otherwise i don't see a simpler way to implement this.

        1 Reply Last reply
        0
        • C Colin Angus Mackay

          The second is a result of the first. Test[i][j] can be broken down like this:

          B someB = someA[i];
          object result = someB[j];

          or it can be written in a compressed form like this:

          object result = someA[i][j];

          The classes look like this:

          public A
          {
          public B this[int index]
          {
          get
          {
          return stuff
          }
          }
          }

          public B
          {
          public object this[int index]
          {
          get
          {
          return stuff
          }
          }

          }

          Does this help?


          Upcoming Scottish Developers events: * UK Security Evangelists On Tour (2nd November, Edinburgh) * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

          A Offline
          A Offline
          Andrei Ungureanu
          wrote on last edited by
          #4

          Thanks a lot. It really works :-D

          Do your best to be the best

          1 Reply Last reply
          0
          • A Andrei Ungureanu

            Hi, I have a small problem. I want to create 2 properties to one of my classes. All I want is to make easier for the users of my class to get some data out of my class. I want when a user writes

            Test[i]

            to get some data and when the user writes

            Test[i][j]

            to get another type of response. I need a little help with the second type of property:

            public class Test
            {
            //some data

            public object this[int index]
            {
            get
            {
            //get data
            }
            }
            }

            This one works. My question is how to write the second one? Thanks in advance

            Do your best to be the best

            I Offline
            I Offline
            Insincere Dave
            wrote on last edited by
            #5

            Why don't you add another indexer with 2 parameters.

            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