J
Jon Skeet [C# MVP]
codymanix said:I agreed that the encoding class could benefit from static indexers but
generally I don't like indexers for uses like that.
You seem to be inconsistent here: either the Encoding class would
benefit from it, *or* (as you said before) it doesn't fit. I don't see
how you can have it both ways, being both a good thing and a bad thing
at the same time.
In my opinion as I said, indexers should only be used when writing
wrappers for array like classes like matrices.
I think that's a bit of a narrow usage pattern, myself. Does Hashtable
fit into that? It's not really an array-like class, in that the index
isn't necessarily a number...
I didn't mean overloading I meant something like that:
int this[int i, string a, double b]
{
get {return GetVal(i,a,b);}
}
I thought that mixing different parameter types would be not possible with
an indexer.
But I was wrong anyway: I tried it and it compiled without problems. If
somebody had asked be before
introducing this feature I'd have said that they should leave it out since
it leads to misuse of indexers.
So you don't like dataRow[columnName, DataRowVersion.Current] either?
It seems pretty reasonable to me.
imagine what happens if a noob discovers that using indexers has the
advantage that you don't have to write method names.
consider a class with 20 overloads of the indexer, every overload does a
completely different task.
welcome to the IOC#CC - international obfuscates c# code contest![]()
Sure, they can write bad code. Then again, they could write every
method with the same name instead, which is just as bad.