In the following program, think of A
is a class provided through dlls and so there is no way to change it. Class B
needs to be derived from A. It has to implement the abstract class's indexer. But the indexer has only a get
section and I also need a set
section which is not allowed for the implementation. So I tried to add an indexer with long
parameter type to complement the the overridden indexer. But now, int a = b[10]
has an error in the following program. What is wrong and how can I remove this error?
abstract class A
{
public abstract int this[int i] { get; }
}
class B : A
{
public int a;
public override int this[int i]
{
get => i;
}
public int this[long i]
{
set => a = value;
}
}
class Program
{
static void Main()
{
B b = new B();
int a = b[(int)10];
}
}
Removing long
indexer removes the error! Why does it hide the int
indexer completely?