---
title: "Indexer in C#"  
description: "In this blog, I’m explaining about Indexer in C#  An indexer allows the programmer to create a class that can act like virtual arrays.We can access in"  
author: "priyanka kushwaha"  
published: 2015-03-11  
updated: 2018-02-22  
canonical: https://www.mindstick.com/blog/832/indexer-in-c-sharp  
category: ".net"  
tags: ["c#", "index"]  
reading_time: 1 minute  

---

# Indexer in C#

In this blog, I’m explaining about [Indexer](https://www.mindstick.com/blog/103/indexer-in-c-sharp) in C#\

- An indexer allows the programmer to create a [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp) that can act like [virtual](https://yourviews.mindstick.com/view/81341/the-oh-so-fight-for-democracy-virtual-rally-scenes) arrays.
- We can [access](https://www.mindstick.com/articles/12994/how-foreigners-can-access-blocked-websites-in-china) [instances](https://answers.mindstick.com/qa/92508/how-can-you-hide-the-sql-server-instances) of those classes using the [] [array](https://www.mindstick.com/articles/335/jagged-array-in-c-sharp-dot-net) access operator.
- An indexer can have [private](https://www.mindstick.com/blog/11097/java-access-modifiers-the-public-and-the-private-modifiers), public, protected or [internal modifier](https://www.mindstick.com/forum/33473/what-is-internal-modifier-in-c-sharp) & the return type can be any valid C# types.
- An indexer in c# must have at [least](https://yourviews.mindstick.com/story/1471/5-autobiographies-you-should-read-at-least-once) one parameter.

##### Example:

```
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks; namespace IndexersExample{       class Program    {        static public string[] namelist = new string[0];        public string this[int index]        {            get            {                string temp;                if (index >= 0 && index < namelist.Length)                    temp = namelist[index];                else                    temp = "";                return (temp);            }            set            {                if (index >= 0&& index < namelist.Length) namelist[index] = value;            }        }        static void Main(string[]args)        {            Programobj = new Program();            int size;            Console.WriteLine("Enter Array size");            size=Convert.ToInt32(Console.ReadLine());            namelist = new string[size];            for (int i = 0; i <namelist.Length; i++)            {                Console.WriteLine("Enter string");                obj[i] = Console.ReadLine();            }            Console.WriteLine("----------Output---------");            for (int i = 0; i <= namelist.Length; i++)            {                Console.WriteLine(obj[i]);            }            Console.ReadKey();        }    }} Output:Enter Array size3Enter stringAbcEnter stringXyzEnter stringOpq----------Output-------------AXyzOpq
```

---

Original Source: https://www.mindstick.com/blog/832/indexer-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
