Home Dashboard Directory Help
Search

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


Status: 

Closed
 as Fixed Help for as Fixed


7
0
Sign in
to vote
Type: Suggestion
ID: 646007
Opened: 2/22/2011 2:33:54 AM
Access Restriction: Public
0
Workaround(s)
view

Description

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]
    {
        get;
    }

    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.
Details
Sign in to post a comment.
Posted by Microsoft 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!

Thanks,
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(http://support.microsoft.com)
Sign in to post a workaround.