By 22/07/2015 8 Comments

C# Indexers In Interface

  • In C#, like methods and properties an interface can also define the indexers.
  • Indexers in an interface have not their body, they have only declaration.


  • Indexers in an interface have not complete implementation, they only have their declaration.


using System;
namespace csharpBasic
    // An interface declaration.
    interface ITechnology
        // An indexer declaration.
        string this[int locationIndex]

    // Technology class implements ITechnology interface.
    class Technology : ITechnology
        // string type instance array field with private access.
        private string[] ProgramingLanguages = new string[6];

        /* Read only property declaration (IndexerLength) 
          of an int type which returns the length of an array. */
        public int IndexerLength
                return ProgramingLanguages.Length;

        // One-dimensional string type indexer declaration.
        public string this[int locationIndex]
        { // Start an indexer scope.

            { // get accessor returns an array field.
                return ProgramingLanguages[locationIndex];

            { // set accessor declaration.

                ProgramingLanguages[locationIndex] = value;
        } // End of an indexer scope.

    class Program
        static void Main(string[] args)
            // Technology object is created.
            Technology technology = new Technology();

            // Sring values are assigned in each indexer location.
            technology[0] = "";
            technology[1] = "Css3";
            technology[2] = "Html5";
            technology[3] = "TypeScript";
            technology[4] = "Php";
            technology[5] = "Jquery";

            // for loop loops through each array elements/values and display them.
            for (int countIndex = 0; countIndex < technology.IndexerLength; countIndex++)

    /*  The Output will be:


Next Tutorial →

← Previous Tutorial

Posted in: C# Advance, C#.NET

Leave your valuable Comment

Have a natural attraction for women cosmetics and replica watches uk clothes, no
more than two for men the most attractive one, is to make their own driving experience, happy and can serve as the facade of the car, another is to highlight the taste edify sentiment rolex replica watch. The replica rolex is undoubtedly the most fashionable accessories, wear a suit to attend the activities, but also get a decent match on the replica watches .