Tech Off Post

Single Post Permalink

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

    stevo_ said:
    TommyCarlier said:
    *snip*
    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).

    No it wouldn't have to support index-based access. Just look at ICollection<T>: you can enumerate it (via IEnumerable<T>), it has a Count-property, but also an Add(T)-method and some additional members (like Remove() and IsReadOnly). Yet it doesn't have index-based access. That's what IList<T> is for.

    Now: IEnumerable<T> « ICollection<T> « IList<T>
    What I'd like: IEnumerable<T> « ICountEnumerable<T> « ICollection<T> « IList<T>