SIGN UP MEMBER LOGIN:    
ARTICLE

INDEXER in C#

Posted by Senthurganesh Ramkumar Articles | Visual C# September 17, 2007
Through this article you will learn the concept of INDEXER in C#.
Reader Level:

INDEXER IN C#:

 

In c# introduce new concept is Indexer. This is very useful for some situation. Let as discuss something about Indexer.

  • Indexer Concept is object act as an array.
  • Indexer an object to be indexed in the same way as an array.
  • Indexer modifier can be private, public, protected or internal.
  • The return type can be any valid C# types.
  • Indexers in C# must have at least one parameter. Else the compiler will generate a compilation error.

this [Parameter]

{

    get

    {

        // Get codes goes here

    }

    set

    {

        // Set codes goes here

    }

} 

 

For Example:

 

using System;

using System.Collections.Generic;

using System.Text;

 

namespace Indexers

{

    class ParentClass

    {

        private string[] range = new string[5];

        public string this[int indexrange]

        {

            get

            {

                return range[indexrange];

            }

            set

            {

                range[indexrange] = value;

            }

        }

    }

 

    /* The Above Class just act as array declaration using this pointer */

 

    class childclass

    {

        public static void Main()

        {

            ParentClass obj = new ParentClass();

 

            /* The Above Class ParentClass  create one object name is obj */

 

            obj[0] = "ONE";

            obj[1] = "TWO";

            obj[2] = "THREE";

            obj[3] = "FOUR ";

            obj[4] = "FIVE";

            Console.WriteLine("WELCOME TO C# CORNER HOME PAGE\n");

            Console.WriteLine("\n");

 

            Console.WriteLine("{0}\n,{1}\n,{2}\n,{3}\n,{4}\n", obj[0], obj[1], obj[2], obj[3], obj[4]);

            Console.WriteLine("\n");

            Console.WriteLine("ALS.Senthur Ganesh Ram Kumar\n");

            Console.WriteLine("\n");

            Console.ReadLine();

        }

    }

}

Login to add your contents and source code to this article
share this article :
post comment
 

ur explanation is good, i hope u continue the same.thank you.

Posted by mohammed muddin Nov 26, 2010

simple....

Posted by Md Mostafijur Rahman Nov 16, 2008
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Team Foundation Server Hosting
Become a Sponsor