Tech Off Post

Single Post Permalink

View Thread: How about some syntax sugar for IEnumerable<>?
  • User profile image
    stevo_

    TommyCarlier said:
    One thing I sometimes miss is an interface between IEnumerable<T> and ICollection<T> that represents a read-only collection (implements IEnumerable<T>) with a Count-property. Something like this:
    public interface IReadOnlyCollection<T>
     : IEnumerable<T>
    {
        int Count { get; }
    }
    If it supports count would it not also support indexed based access? and I agree.. personally readonlycollection makes me cringe.. I don't like exposing it, and it can only ever then act as runtime protection.. I would love some readonly interfaces for data structures.. and perhaps even some immutable data structure interfaces and implementations (surely the implementations already exist in f# for example).