Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

New interfaces IReadOnlyList and IReadOnlyDictionary

$
0
0

Hello,

I apploud to the long-awaited intoduction of interfaces for read-only collections.

However, I also have some questions. First of all, why there's no general IReadOnlyCollection interface.

 

    public interface IReadOnlyCollection<out T> : IEnumerable<T>
    {
        int Count { get; }
    }

While I understand the resistance to add another interface for collections, there's a real lack of an interface for non-lazy read-only collection. IEnumerable may not serve that role. Introduction of IReadOnlyList and IReadOnlyDictionary is the last chance to also introduce IReadOnlyCollection, it would be almost impossible to introduce it afterwards, as it would mean that some classes that explicitly implement IList, IReadOnlyList and (independently of IReadOnlyList) IReadOnlyCollection have to implement Count trice.

 

Second question is about LINQ support for these interfaces. Will Enumerable.Count() be updated to check for these interfaces on sequences that do not support ICollection? Failing to do so, would mean that there's no way to have immutable collections with immutability visible from their interface (as collections will be forced to implement ICollection to support Enumerable.Count efficiently). 

And the third one. I understand that the support for these interfaces was driven by WinRT requirements. However these interfaces are usefull without WinRT as well. So, will other collections besides List<> and Dictionary<> be updated to support these interfaces?



Viewing all articles
Browse latest Browse all 8156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>