what is indexe? why we use it?
what is indexer in c# and how and why we use that in C#?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Govinda Rajulu YemineniPosted Jul 17, 2015, 7:45 AM
Rajeesh MenothPosted Jul 17, 2015, 7:17 AM
Nilesh JadavPosted Jul 17, 2015, 4:56 AM
Indexers are one neat feature of C#. They allow us to access a particular class as it is an array. They are similar to the properties in means that they encapsulate method calls into more convenient representation of value access and value setting. Declaring a property you can access it with its name, so it behaves like variable. The indexer is actually a class so it behaves as a type, i.e. you have to declare a variable of its type (actually to instantiate an object from it, but all variables are objects anyway). Indexers are also called smart arrays in C# and can be used to treat an object as an array. An indexer allows an instance of a class or a struct to be indexed as an array, which is useful for looping or iterating or data binding operations. The following is the syntax of an indexer declaration.
{}Set{}}All indexers should accept at least one parameter. Indexers cannot be static. This is because static methods do not have access to ‘this’. The ‘this’ keyword indicates an instance of the current class.Sivaraman DhamodaranPosted Jul 17, 2015, 4:24 AM