---
title: "Indexer in C#"  
description: "An indexer is worked as properties. Indexers allow instancesof a class or struct to be indexed just like arrays. Indexers are also calledsmart arrays"  
author: "Amit Singh"  
published: 2011-01-25  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/103/indexer-in-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Indexer in C#

An [indexer](https://www.mindstick.com/blog/11315/indexer-in-c-sharp-with-example) is [worked as](https://yourviews.mindstick.com/view/86510/henry-kissinger-passes-away-at-100-worked-as-a-us-secretary) properties. Indexers allow instancesof a class or [struct](https://www.mindstick.com/blog/83/struct-in-c-sharp-dot-net) to be indexed just like arrays. Indexers are also calledsmart [arrays in C#](https://www.mindstick.com/forum/159856/how-to-create-and-work-with-arrays-in-c-sharp) and can be used to treat an object as an array.

##### Syntax for an indexer declaration

Modifier returnType this[argument]

##### Some point for indexers

· Indexers [concept](https://www.mindstick.com/blog/79/routing-concept-in-dot-net) is object act as an array.

· thiskeyword is used to [define](https://yourviews.mindstick.com/audio/1110/lifestyles-choices-that-define-our-lives) the indexers.

· A get accessor returnsa value and A set accessor assigns a value.

· Indexers cannot be [static](https://www.mindstick.com/articles/12098/the-static-keyword-the-static-methods).

· Indexers can be abstract. There would be no codeinside it in such a case.

· The return type can be any valid C# types

##### For example:

This is thesimple example how use the [indexers in c#](https://www.mindstick.com/forum/161762/what-are-indexers-in-c-sharp)

```
class Program{   static void Main(string[]args)   {         yyya = new yyy();         a[1] = 24;              }}public class yyy{   public int this[int i]   {      set      {          Console.WriteLine("The value of array a[" + i + "]: " + value);          Console.ReadLine();       }   }}
```

\

##### Output:

The value of array a[1]: 24

---

Original Source: https://www.mindstick.com/blog/103/indexer-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
