Posts

Showing posts with the label C# Indexers

C# Indexers

An indexer allows an instance of a class or struct to be indexed as an array. If the user will define an indexer for a class, then the class will behave like a virtual array. Array access operator i.e ( [ ] ) is used to access the instance of the class which uses an indexer. A user can retrieve or set the indexed value without pointing an instance or a type member. Indexers are almost similar to the  Properties .  The main difference between Indexers and  Properties  is that the  accessors  of the Indexers will take parameters. In the above syntax: access_modifier:  It can be public, private, protected or internal. return_type:  It can be any valid C# type. this:  It is the keyword which points to the object of the current class. argument_list:  This specifies the parameter list of the indexer. get{ } and set { }:  These are the  accessors . // C# program to illustrate the Indexer using System; // class declaration class Indexe...