
Why only static operators and nonstatic indexers?
CSharp reference says that operators have to be static but
indexers can't be static.
But what can you do if you really what to use an indexer in an operator?
(Of course I can define a static _get and _set method and call them inside
the indexer - but thats not very nice and has some runtime overhead)
class A {
public static A operator + (A a1, A a2) {
..... use _get and _set here instead the indexer directly
}
public int A[int i] {
get {
return _get(i);
}
set {
_set(i, value);
}
}
private static int _get(int i) {
return 0;
}
private static void _set(int i, int val) {
}
Quote:
}
Any suggestion?