Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

What are Indexer in C# .Net?

user-image
Question added by Mohannad Bakbouk , Full Stack Web Developer , Almohtaseb
Date Posted: 2016/10/20
Bineesh VP
by Bineesh VP , Software Developer , Unknown

Indexers are a syntactic convenience that enable you to create a class , struct or interface that client applications can access just as an array. Indexers are most frequently implemented in types whose primary purpose is to encapsulate an internal collection or array. For example, suppose you have a class named TempRecord that represents the temperature in Farenheit as recorded at 10 different times during a 24 hour period. The class contains an array named "temps" of type float to represent the temperatures, and a datetime that represents the date the temperatures were recorded.

anas alhashki
by anas alhashki , Senior Full Stack Engineer , Industrial Motor Power Corporation

Indexers allow your class to be used just like an array.

On the inside of a class, you manage a collection of values any way you want.

These objects could be a finite set of class members, another array, or some complex data structure.

Regardless of the internal implementation of the class, its data can be obtained consistently through the use of indexers.

Mohannad Bakbouk
by Mohannad Bakbouk , Full Stack Web Developer , Almohtaseb

Indexer allows classes to be used in more intuitive manner. C# introduces a new concept known as Indexers which are used for treating an object as an array. The indexers are usually known as smart arrays in C#. They are not essential part of object-oriented programming.An indexer, also called an indexed property, is a class property that allows you to access a member variable of a class using the features of an array.Defining an indexer allows you to create classes that act like virtual arrays. Instances of that class can be accessed using the [] array access operator.

More Questions Like This

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.