Add an IIndexable<T> (accessible by index) interface - by Daniel_Katz

Status : 

  Fixed<br /><br />
		This item has been fixed in the current or upcoming version of this product.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 646007 Comments
Status Closed Workarounds
Type Suggestion Repros 0
Opened 2/22/2011 2:33:54 AM
Access Restriction Public


Currently most of the common collections in BCL are implementing the IEnumerable<T> interface. This allows a great deal of flexibility.

But, IEnumerable is very costly on operations such as IEnumerable<T>.Count<T>(), IEnumerable<T>.Last<T>() and many others.

I'd like to propose to introduce a new interface that supports indexing, as I call it – IIndexable<T> which can be defined as:

public interface IIndexable<out T> : IEnumerable<T>
    T this[int index]

    int Count { get; }

It will improve the performance of linq extensions on all the supporting collections.
All the types that implement the ICollection<T> interface will be naturally compatible with IIndexable<T>.

The advantage of IIndexable<T> over ICollection<T> will be that IIdexable<T> is read-only as IEnumerable<T>, hence – can be covariant as IEnumerable<T> and avoid many casting issues.
Sign in to post a comment.
Posted by Immo [MSFT] on 4/29/2011 at 8:35 AM
Hi Daniel_Katz,

Thank you very much for the suggestion. In fact, we are already planning to include a covariant read-only list interface in the upcoming release of the .NET Framework which wil hopefully address your need.

Please keep the suggestions coming!

Immo Landwerth
Program Manager
BCL Team
Posted by Microsoft on 2/22/2011 at 3:13 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(