Why can’t you create a generic indexer in .NET?
the following code throws a compiler error:
public T this<T>[string key] { get => /* Return generic type T. */ }
Does this mean you can’t create a generic indexer for a generic member collection?
The only thing I can think of this can be used is something along these lines:
But this doesn’t actually buy you anything. You’ve just replaced round parentheses (as in
(int)settings['timeout']) with angle brackets, but received no additional type safety as you can freely doIf you have something that’s strongly but not statically typed, you might want to wait until C# 4.0 with its dynamic keyword.