Indexers
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# community.
Defining a C# indexer is much like defining properties.
An indexer is a member that enables an object to be indexed in the same way as an array.
Indexer modifier can be private, public, protected or internal
The return type can be any valid type in C#
Indexers in C# must have at least one parameter. Else the compiler will generate a compilation error.
Syntax for Indexers
Defining a property involves providing a property name.
Indexers are not defined with the names but with the ‘this’ keywords, which refers to the object instance.
Public return type this[parameter type index]
{ Get{ // return the value from the specified index } Set{ // set values at the specified index }
}
ankpro
ankpro training
Asp.net MVC
C#
C sharp
Bangalore
Rajajinagar
Selenium
Coded UI
Mobile automation testing
Mobile testing
JQuery
JavaScript
.Net
Components of the .Net framework
Hello World
Literal
Keywords
Variable
Data types
Operators
Branching
Loops
Arrays
ArrayList
Strings
String Builder
Structures
Enums
Functions
Classes
Inheritance
Polymorphism
Properties
Indexers
Events
Nested Classes
Delegates
Anonymous methods
Labda expressions
Abstract classes
Exception Handling
Linq
Interfaces
Extension methods
Anonymous types
Generics
Collections
Garbage Collection
Reflection
Attributes
Input and output statements
Type casting
Partial Methods
Partial Classes
Boxing and Unboxing
Var vs Dynamic vs Object