Category Archives: Code

Code is a question and answer site for professional and enthusiast programmers.

Why it is not possible to define generic indexers in .NET?

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?

Why it is not possible to define generic indexers in .NET?