Results 1 to 4 of 4

Thread: What is meaning for Indexers in C# ?

  1. #1
    Join Date
    Nov 2009
    Posts
    81

    What is meaning for Indexers in C# ?

    I have begin to study C# (C Sharp) from the last month. I am very much impressed with its concepts. I have earlier studied C++ and Java. But C# is also quite interesting. Now I have be given an assignment on Indexers in C#. I have been searching alot on this concept but still not finding a good explanation for it.

  2. #2
    Join Date
    May 2008
    Posts
    2,012

    Re: What is meaning for Indexers in C# ?

    C sharp has introduced many new concepts of which one is termed as Indexers. These are basically used for handling an object as an array. Another name for Indexers is smart arrays. In other words, we can put it as an Indexer is a member which allows an object to be indexed in the same way as that of an array.

  3. #3
    Join Date
    Jan 2008
    Posts
    1,521

    Re: What is meaning for Indexers in C# ?

    General Sytax for Indexer is as follows:

    Code:
     <modifier> <return type> this [argument list]
     {
    
      get
      {
       .
       .
       .
      }
      set
      {
       .
       .
       .
      }
    
     }
    eg.

    Code:
    using System;
    using System.Collections;
    
    class pqr
    {
     private string []info = new string[4];
     public string this [int index]
     {
      get
      {
       return info[index];
      }
      set
      {
       info[index] = value;
      }
     }
    }
    
    
    class Abc
    {
     public static void Main()
     {
      pqr p = new pqr();
      p[0] = "India";
      p[1] = "Kashmir";
      p[2] = "B008";
      p[3] = "Delhi";
     Console.WriteLine("{0},{1},{2},{3}",p[0],p[1],p[2],p[3]);
     }
    }

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: What is meaning for Indexers in C# ?

    The concept of Indexers in C# is very easy to understand. They permit your class to be used just like an array. We can simply say that Indexers allow instances of your class or struct to be indexed in the same way as arrays. Indexers are similar to properties except that their accessors take parameters. With the help of an Indexer one can use an index on an object to obtain values stored within the object. Thus by using Indexer you can easily organise your data and get it easily.

Similar Threads

  1. Meaning of growl in Apple Mac OSX.
    By Acardi !! in forum Windows Software
    Replies: 3
    Last Post: 06-09-2011, 11:51 PM
  2. What is the meaning of function($) in java?
    By Steadfast in forum Software Development
    Replies: 5
    Last Post: 22-02-2010, 09:08 PM
  3. what is the meaning of countrylist.split()?
    By hounds in forum Software Development
    Replies: 4
    Last Post: 12-02-2010, 10:32 PM
  4. Indexers in C sharp
    By Mithun Seth in forum Software Development
    Replies: 5
    Last Post: 19-01-2010, 09:37 AM
  5. What is actually the meaning of properties for C#?
    By Joel5 in forum Software Development
    Replies: 3
    Last Post: 11-11-2009, 10:39 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,991,344.29339 seconds with 16 queries