What is the real use of indexer in C#?
It looks pretty confusing as I am a new c# programmer. It looks like an array of objects but it\'s not.
Indexers allow instances of a class or struct to be indexed just like arrays, they are most frequently implemented in types whose primary purpose is to encapsulate an internal collection or array.
A get accessor returns a value and a set accessor assigns a value:
public T this[int i]
{
get
{
return arr[i];
}
set
{
arr[i] = value;
}
}
With the enums, they defined values are limited to a small set of primitive integral types (byte, sbyte, short, ushort, int, uint, long, ulong).
The char type is also a integral type, but it differs from the other integral types in two ways:
There are no implicit conversions from other types to the char type. In particular, even though the sbyte, byte, and ushort types have ranges of values that are fully representable using the char type, implicit conversions from sbyte, byte, or ushort to char do not exist.
Constants of the char type must be written as character-literals or as integer-literals in combination with a cast to type char. For example, (char)10 is the same as '\x000A'.
(C# Language Specification 3.0, Section 4.1.5)