Reputation: 11689
As the title states, I would like to declare an indexer object this[int index]
in an abstract class as an abstract member.
Is this possible in any way? Is it possible to declare this in an interface too?
Upvotes: 13
Views: 3230
Reputation:
You may declare it like this:
internal abstract class Hello
{
public abstract int Indexer[int index]
{
get;
}
}
Then you'll have the option to override only get
or override both get
and set
.
Upvotes: 0
Reputation: 3827
public abstract class ClassWithAbstractIndexer
{
public abstract int this[int index]
{
get;
set;
}
}
Upvotes: 21
Reputation: 273274
A simple example:
public interface ITest
{
int this[int index] { get; }
}
public class Test : ITest
{
public int this[int index]
{
get { ... }
private set { .... }
}
}
Several combinations of private/protected/abstract are possible for get
and set
Upvotes: 2