I am wondering whether it is allowed in C# to provide the IndexerName
attribute defining the same name for overloaded indexers which have the same semantics. Say, for example, that you have a wrapper class for matrices of unknown size which defines two indexers, one for Int32
and one for Int64
array access:
using System.Runtime.CompilerServices;
public class Matrix
{
private double[,] content;
[IndexerName("Cells")]
public double this[int row, int column]
{
get { return this.content[row, column]; }
set { this.content[row, column] = value; }
}
[IndexerName("Cells")]
public double this[long row, long column]
{
get { return this.content[row, column]; }
set { this.content[row, column] = value; }
}
}
So obviously, the indexers do not differ in their semantics, but in their arguments. The code will not compile, as now, the Matrix
type already contains a definition for 'Cells'. Is it even valid to use the IndexerName
attribute in this situtation or do I have a wrong understanding of this attribute?