In my last column, I discussed how the Microsoft .NET Framework (and its compilers) use interfaces to implement behavior that crosses many different kinds of objects. My example in that column was using the IEnumerable interface in one of your classes to allow your class to work with a For...Each loop. I showed how you could use that knowledge to create a read-only collection. But I also pointed out that creating your own read-only collection was sort of pointless: The .NET Framework already provides the ReadOnlyCollectionBase class to let you create custom read-only collections, and it includes the AsReadOnly extension method for creating read-only collections from existing read-write collections.
May 10, 13